Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get output from unix command with Streamgobbler? 1

Status
Not open for further replies.

pvjmarar

Programmer
Feb 6, 2004
1
GB
Hi,
I'm new to Java programming. I need to run unix commands with Java and capture the outputs. From the postings in various forums I got the answer..to use Runtime.exec and StreamGobbler. But the method run() of StreamGobbler does not return anything. In fact I need to call this method from different classes which run different unix commands and produce outputs which are integers or strings..I need to use these values for further processing, rather than just printing out. I also found a method getCapturedOutput which returns a String, but don't know how to use..Waiting for your valuable suggestions..

-J
 
I've never heard of the "StreamGobbler" class - probably some 3rd party api, but you may read IO streams from the Process object as such :

Process p = Runtime.getRuntime().exec("ls");
InputStream is = p.getInputStream();
OuputStream os = p.getOutputStream();


This will in effect give you an IO handle to the OS call ...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top