dcsimg
command output redirection problem under redhat 9
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

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

Re: command output redirection problem under redhat 9

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, February 26, 2004 05:10 PM

I don't know but perhaps you need to explicitly invoke a shell, e.g. "sh" or "bash" or "ksh", since it is the shell that handles redirection.

About | Sitemap | Contact