K
Kin C. Wong
I am attempting to create a GUI that starts up and monitors 2 other
java programs (running as separate processes on a windows machine). I
am using the GUI to start one of the processes as follows (the other
is started in a similar fashion):
process = "java SSSP_Server.Server";
Runtime rtPrimary = Runtime.getRuntime();
Process pidPrimary = rtPrimary.exec(process);
dataInPrimary = new
DataInputStream(pidPrimary.getInputStream());
getPrimaryMessages(); // thread to listen for input
The getPrimaryMessages() is a thread that listens for the output of
the new process that was created. The listing for that method is:
//doGetPrimaryMessages is a boolean that is initialized to true.
private void getPrimaryMessages() {
Runnable getMessage = new Runnable() {
public void run() {
while (doGetPrimaryMessages) {
try {
String message = dataInPrimary.readUTF();
updateDisplaySafely(message);
} catch (IOException ioe) {
doGetPrimaryMessages = false; // Causes this
thread to stop.
}
}
}
};
The problem is that I'm not getting anything from the input stream. In
pidPrimary I am just using System.out.println() to write to the std
output. Is the output of the the pidPrimary process somehow blocked
because it is running through the JVM? I've also tried putting the
line "start java SSSP_Server.Server" into a bat file and calling the
bat file to start the process, but I get the same result.
Am I doing something wrong or is this not the way to communicate
between processes? I know I could use sockets, but the purpose of the
GUI is to just provide a single window to view the status messages of
the 2 processes I'm running. The GUI doesn't really need to talk to
the processes other than to start them up.
Thanks in advance for any information.
- Kin
java programs (running as separate processes on a windows machine). I
am using the GUI to start one of the processes as follows (the other
is started in a similar fashion):
process = "java SSSP_Server.Server";
Runtime rtPrimary = Runtime.getRuntime();
Process pidPrimary = rtPrimary.exec(process);
dataInPrimary = new
DataInputStream(pidPrimary.getInputStream());
getPrimaryMessages(); // thread to listen for input
The getPrimaryMessages() is a thread that listens for the output of
the new process that was created. The listing for that method is:
//doGetPrimaryMessages is a boolean that is initialized to true.
private void getPrimaryMessages() {
Runnable getMessage = new Runnable() {
public void run() {
while (doGetPrimaryMessages) {
try {
String message = dataInPrimary.readUTF();
updateDisplaySafely(message);
} catch (IOException ioe) {
doGetPrimaryMessages = false; // Causes this
thread to stop.
}
}
}
};
The problem is that I'm not getting anything from the input stream. In
pidPrimary I am just using System.out.println() to write to the std
output. Is the output of the the pidPrimary process somehow blocked
because it is running through the JVM? I've also tried putting the
line "start java SSSP_Server.Server" into a bat file and calling the
bat file to start the process, but I get the same result.
Am I doing something wrong or is this not the way to communicate
between processes? I know I could use sockets, but the purpose of the
GUI is to just provide a single window to view the status messages of
the 2 processes I'm running. The GUI doesn't really need to talk to
the processes other than to start them up.
Thanks in advance for any information.
- Kin