1

I'm getting null as the output of this command line.

Process result = Runtime.getRuntime().exec(new String[]{"/usr/bin/find",baseDir+"/..","-type","f","|","/usr/bin/grep",filter1,"|","/usr/bin/grep",filter2,"|","/usr/bin/wc","-l"});
result.waitFor();
BufferedReader echo = new BufferedReader(new InputStreamReader(result.getInputStream()));
writer.print(echo.readLine());
echo.close();

Is it the pipes "|"?

arodriguezdonaire
  • 5,396
  • 1
  • 26
  • 50
dacracot
  • 22,002
  • 26
  • 104
  • 152

1 Answers1

3

To get the shell commands like |, use /bin/bash as your first argument to exec, -c as the second, and the entire string (including find, it's parameters and the pipe etc) as the third.

Process result = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "/usr/bin/find " + baseDir+"/.. -type f | /usr/bin/grep " +filter1 + "| /usr/bin/grep "+filter2+" | /usr/bin/wc -l"});
Ma Ha
  • 17
  • 4
PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56