Capturing screen messages from Runtime.getRuntime().exec("myprogram")

S

sinleeh

Dear All,

I need to run a command line program inside my java program. Hence, I
have to use

Process proc = Runtime.getRuntime().exec("myprogram");

to run the command line program for me.

Unfortunately, I have to cache and interpret output from "myprogram".
The output can be very long and therefore can cause buffer overflow. It
can come from either the outputstream or the errorstream. I see that
Java provide Process.getOutputStream() and Process.getErrorStream() for
this purpose but I have problem reading data out from them. Can someone
point me to the correct direction please?

Many thanks and best regards
Sinleeh
 
O

Oliver Wong

Unfortunately, I have to cache and interpret output from "myprogram".
The output can be very long and therefore can cause buffer overflow. It
can come from either the outputstream or the errorstream. I see that
Java provide Process.getOutputStream() and Process.getErrorStream() for
this purpose but I have problem reading data out from them. Can someone
point me to the correct direction please?

You can't read from an OutputStream. use Process.getInputStream()
instead.

If the data is big enough to cause buffer overflow, you might want to
create a dummy thread which just reads from the output stream and writes to
your own internal buffer. Or failing that, save the output to a file to be
processed later.

- Oliver
 
R

Roedy Green

Unfortunately, I have to cache and interpret output from "myprogram".
The output can be very long and therefore can cause buffer overflow. It
can come from either the outputstream or the errorstream. I see that
Java provide Process.getOutputStream() and Process.getErrorStream() for
this purpose but I have problem reading data out from them. Can someone
point me to the correct direction please?

See http://mindprod.com/jgloss/exec.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top