Consider the following code:
String commandf = \"ls /etc | grep release\"; try { // Execute the command and wait for it to complete Process child =
Write a script, and execute the script instead of separate commands.
Pipe is a part of the shell, so you can also do something like this:
String[] cmd = { "/bin/sh", "-c", "ls /etc | grep release" }; Process p = Runtime.getRuntime().exec(cmd);