Hi all.
Under blackdown's JDK1.1.7 v1a for linux an echo program
will not work if it is run from a shell script. The same
code will work perfectly if run without the -native
argument or directly from the command line. The problem
seems to be that a call to System.in.read() will block
and never return. Here is an example that shows the
problem. I also found it interesting that the program
would not be killed by a Ctrl-C when run from the
script with the -native argument. Another strange thing
I noticed is that it will work correctly if the program
is run from the shell script like this "exec java ...".
(shell script used to start program)
#!/bin/sh
java -native echo
(java source file echo.java)
public class echo {
public static void main(String[] argv) throws Exception {
System.out.println("Please begin typing, type quit to stop");
while (true) {
int avail = System.in.available();
if (avail < 0) {
throw new Exception("System.in.available() returned " + avail);
} else if (avail == 0) {
Thread.currentThread().sleep(100);
} else {
byte[] buff = new byte[avail];
System.in.read(buff);
// quit if they typed "quit"
if ((buff.length == 5 || buff.length == 6) &&
buff[0] == 'q' && buff[1] == 'u' &&
buff[2] == 'i' && buff[3] == 't') {System.exit(0);}
// echo back what was just typed
System.out.println("-----ECHO BEGIN-----");
System.out.write(buff);
System.out.println("-----ECHO END-----");
System.out.println();
}
}
}
}
I hope that helps
mo dejong
dejong at cs.umn.edu