external process and redirecting its streams

M

Marteno Rodia

Hello,
In my program, I want to launch another Java program on another JVM...
The way how I try to do it and the problem I experienced is as
follows:

1) Primary is another class in my project and is executable...

2) I try to start its main method in the following way:
Process proc = Runtime.getRuntime().exec("java Primary");
or:
String[] cmdArray = {"java", "Primary"};
Process proc = Runtime.getRuntime().exec(cmdArray);

3) Then I try to read process' streams in a separate thread.
4) In the main thread program stops at proc.waitFor() and execution
doesn't resume...
5) In the "reading" thread, the function which blocks execution is
BufferedReader.readLine() (I would rather expect it to return null in
the worst case... but I have even used the BufferedReader.ready()
method and I believe I wait if the buffer is empty...)
6) Nothing happens, the program can't finish...

I've been already asking about the apporach I use:
http://groups.google.com/group/comp..._frm/thread/11e367a28a0b41fd/9d69aa5ef2e34211
And I know this (very good, in my opinion) article:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1

First, I wanted to test notions of visibility between Java executable
classes when invoking my program both from NetBeans IDE and as a JAR
from command line... But I can't do it (as I described above).

What is wrong in my approach?
Thanks in advance for your help.

MR
 
M

Marcin Rodzik

A single thread for both output streams, or a thread for each stream?

A single thread. Now I know that is possible, but tricky! :D

One of the streams were empty all the time and it was blocking! The
main reason was that first I was waiting until any of the streams is
ready and then, incidentally, I was trying to read from unready
stream :)

Now I can ask about my main problem... but in a separate thread!

MR
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top