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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Output of console application

Status
Not open for further replies.

zoomby

Programmer
Aug 5, 2002
60
DE
hi

is it possible, in java, to execute a file (a java .class file or any other console application) and fetch its output into a string?

bye
chris
 
If you launch a program using Runtime.exec(), you get back a Process object. You can use getErrorStream() and getOutputStream() on the Process object to extract the output.

There are problems, though. You have to ensure that the program you launch doesn't ever stop and ask for input, even on error conditions. I also had problems when I used a buffer on the output and it would block until sufficient characters came in - it seems to me I ended up making the buffer just a few characters long... "When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top