0

While trying ProcessBuilder.start(), I wanted to figure out if it could parse special characters operators like &, | and < >

So, for example:

String[] cmdarray = new String[]{"whoami"};
Process p = new ProcessBuilder(cmdarray).start();

I get the result

But if I do:

String[] cmdarray = new String[]{"whoami", "&&", "uname", "-a"};
Process p = new ProcessBuilder(cmdarray).start();

I don't get any result.. is there any way to achieve that? Or is it a limitation of ProcessBuilder and Runtime.getRuntime().exec()?

khary
  • 3
  • 3
  • In your example if you read from `p.getErrorStream()` you will get _some_ result, namely the error message telling you that shell-specific syntax like redirection/pipe, control flow and variables isn't handled by ProcessBuilder and Runtime. – dave_thompson_085 Mar 31 '22 at 21:50

0 Answers0