J
Jan Burse
Dear All,
Just running the following test program:
CtrlCRunner ctrl = new CtrlCRunner();
ctrl.installCtrlC(
new Runnable() {
public void run() {
/* do nothing ! */
}
}
);
FileInputStream fs = new FileInputStream(FileDescriptor.in);
byte[] buf = new byte[256];
for (; {
System.out.print("test: ");
int len = fs.read(buf);
String str = new String(buf,0,Math.max(0,len));
System.out.println("len = "+len+", buf = "+str+",
buf[0]="+buf[0]);
if ("exit".equals(str.trim())) break;
}
ctrl.deinstallCtrlC();
Noticed that ^C and ^Z both deliver EOF.
When pressing ^C
test: len = -1, buf = , buf[0]=0
When pressing ^Z and ENTER:
test: ^Z
len = -1, buf = , buf[0]=0
How could I distinguish the two in Java?
Best Regards
BTW: It does not happen on Linux and Mac
OS with ^C and ^D, I only see this happen
currently on Windows 7.
Sounds similar to the following problem:
Inconsistent raw_input behavior after Ctrl-C
http://www.gossamer-threads.com/lists/python/python/781893
Just running the following test program:
CtrlCRunner ctrl = new CtrlCRunner();
ctrl.installCtrlC(
new Runnable() {
public void run() {
/* do nothing ! */
}
}
);
FileInputStream fs = new FileInputStream(FileDescriptor.in);
byte[] buf = new byte[256];
for (; {
System.out.print("test: ");
int len = fs.read(buf);
String str = new String(buf,0,Math.max(0,len));
System.out.println("len = "+len+", buf = "+str+",
buf[0]="+buf[0]);
if ("exit".equals(str.trim())) break;
}
ctrl.deinstallCtrlC();
Noticed that ^C and ^Z both deliver EOF.
When pressing ^C
test: len = -1, buf = , buf[0]=0
When pressing ^Z and ENTER:
test: ^Z
len = -1, buf = , buf[0]=0
How could I distinguish the two in Java?
Best Regards
BTW: It does not happen on Linux and Mac
OS with ^C and ^D, I only see this happen
currently on Windows 7.
Sounds similar to the following problem:
Inconsistent raw_input behavior after Ctrl-C
http://www.gossamer-threads.com/lists/python/python/781893