Trying to execute a command with a pipe in it
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alfred_Wong
Posted On:   Wednesday, January 8, 2003 07:47 AM

Hi, I am trying to execute a command with a pipe to a grep. But java keeps on printing out an error in the error stream that i'm not using the first command properly. My guess is that its hitting the pipe signal and taking it as an argument of the first command and giving me and error. For example, I have command1 and a grep command so I do this String commandString = "command1 | grep something" Process p = RunTime.getRunTime().exec(commandString) As a background there is no security checking so the system can do sub-processes. Can anybody help me out here? Alfred    More>>

Hi,


I am trying to execute a command with a pipe to a grep. But java keeps on printing out an error in the error stream that i'm not using the first command properly. My guess is that its hitting the pipe signal and taking it as an argument of the first command and giving me and error.


For example, I have command1 and a grep command so I do this

			
String commandString = "command1 | grep something"
Process p = RunTime.getRunTime().exec(commandString)


As a background there is no security checking so the system can do sub-processes.



Can anybody help me out here?


Alfred    <<Less

Re: Trying to execute a command with a pipe in it

Posted By:   Anonymous  
Posted On:   Wednesday, January 8, 2003 08:05 AM

I don't know why your execution isn't working. However, another option is to do the pipe yourself by exec-ing two processes, and taking the OutputStream from the first process and sending it to the second's InputStream (which is what the pipe does anyway!)
About | Sitemap | Contact