No subject
Sat Nov 12 19:29:10 PST 2005
console in/out to the slave process's in/out.
After launching the process (using Runtime.exec), I launch three
background threads:
1. Monitor the slave process's getInputStream and write all incoming
bytes to my System.out
2. Monitor the slave process's getErrorStream and write all incoming
bytes to my System.out
3. Monitor my System.in and write all incoming bytes to the slave
process's getOutputStream
The funniness I'm experiencing is in step 3 -- it seems that I have to
press each keystroke TWICE, for it to register into the slave process.
For example, as a test, I am launching "lynx http://www.cnn.com", and
the lynx options "H" and "O" I have to press twice (H-H or O-O) to get
the appropriate screen to pop up. In fact, the first keystroke I enter
doesn't matter; it's as if every other keystroke is looked at.
Here is my code for thread #3:
// -------- Begin code fragment
// Start an input thread
Thread inThread = new Thread() {
public void run() {
OutputStream out = slaveProcess.getOutputStream();
byte[] buffer = new byte[1024];
int len;
while (true) {
try {
len = System.in.read(buffer);
if (len == -1) break;
//System.out.println("Bytes read from keyboard: " + len);
out.write(buffer, 0, len);
out.flush();
} catch (Exception e) {
break;
}
}
System.out.println("inThread exiting");
}
};
inThread.start();
// -------- end code fragment
In reference to some older JVM bugs, I've tried inserting
Thread.currentThread().sleep(1) at various points (in case there is a
scheduler problem), but to no avail.
Any help would be appreciated!
Thank you,
Bryan
More information about the Advanced-java
mailing list