I’m new to Java. I want to use a command
"ps -e > /home/root/workspace/MyProject/ProcessList.txt"
with runTime.exec();
On searching through the web, I came to know that runTime.exec() doesn’t support pipes or redirecting. Please let me know how can I execute this command with my Java code. Please give exact answers.
Pipes and redirection are features provided by the shell. The easy (and dirty) solution is to spawn the command inside a shell:
"/bin/sh -c 'ps -e > /home/root/workspace/MyProject/ProcessList.txt'".Edit: I had forgotten that the default
StringTokenizerdoes not work with quoted strings. Provide arguments as an array of strings.