When you run the command from the shell, the shell interpreter understands that you want to run one program and pipe the output to another. When you use Runtime.exec, it takes the entire command line and throws it at cat. Cat tries to open files like "|" and "-p" and fails. You have to exec the shell and pass it the command as arguments or through standard input. Here is a good article on using Runtime.exec and the pitfalls it contains.