I\'m calling command line programs connected by pipes. All this works on Linux for sure.
My method:
protected String execCommand(String command) thro
The quick-and-dirty thing to do would be:
command = "/bin/sh -c '" + command.replaceAll("'", "'\''") + "'"
Normally, you'll have to watch out for shell injection (i.e. someone sneaks "; rm -rf /;" into the command). But that's only an issue if part of the command can be supplied from some other user input.
The slow and painful approach would be to do the Bash piping yourself in Java. If you go down this road, you'll find out all the wonderful things that Bash gives you that's not directly available from Process.exec (pipes, redirection, compound commands, variable expansion, arithmetic evaluation, ...).
| characters. Be sure to watch out for || and quoted strings.Process for every piped command.Threads that read the output from one command and write it to the input of the next command.