Posted By:
David_Thornton
Posted On:
Thursday, February 26, 2004 03:58 PM
When attempting to redirect the output from system commands to a file using the java.lang.Runtime's exec() method the redirection symbol ">" is incorrectly interpreted as an argument to the command. For example; Process p = Runtime.getRuntime().exec("ls > fred.txt"); results in; /usr/ls >: No such file or directory /usr/ls fred.txt: No such file or directory I have tried passing the command as an array as suggested in this forum (eg String cmd[] = {"ls",">","fred.txt}) but get the same result. I can get around this by using a shell script but the output redirection should work. Any ideas?
More>>
When attempting to redirect the output from system commands to a file using the java.lang.Runtime's exec() method the redirection symbol ">" is incorrectly interpreted as an argument to the command. For example;
Process p = Runtime.getRuntime().exec("ls > fred.txt");
results in;
/usr/ls >: No such file or directory
/usr/ls fred.txt: No such file or directory
I have tried passing the command as an array as suggested in this forum (eg String cmd[] = {"ls",">","fred.txt}) but get the same result. I can get around this by using a shell script but the output redirection should work. Any ideas?
<<Less