ProcessBuilder
was never meant to execute multiple commands. The entries of the List
are treated as arguments and it is the invoked program sh
which executes the one argument due to the -c
option. So it’s the sh
command and it’s -c
option which “decide” to interpret one argument, and only one, as a command to start. But the bash will run multiple commands being provided as a single argument separated by ;
.
List<String> vsArrays = new ArrayList<String>();
vsArrays.add("/bin/sh");
vsArrays.add("-c");
vsArrays.add("echo '123' > ~/1.rad; echo '123' > ~/2.rad; echo '123' > ~/3.rad");
ProcessBuilder proc = new ProcessBuilder(vsArrays);
Process start = proc.start();
start.waitFor();