I have a java program:
public class ProcessMain {
public static final void main(String[] args) throws Exception {
Scanner keyboard = new Scanner(System.in);
boolean exit = false;
do
{ if(keyboard.hasNext()){
String input = keyboard.next();
System.out.println(input);
if( "abort".equals(input)){
ABORT();
exit = true;
}
}else{
System.out.println("Nothing");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}while (!exit);
}
private static void ABORT(){
System.out.println("ABORT!!!!");
}
}
In Linux, a script:
rm testfifo
mkfifo testfifo
cat > testfifo &
echo $!
java -cp "Test.jar" com.example.ProcessMain < testfifo
Terminal A runs the script, "Nothing" can be printed every 5 seconds. And then Terminal B execute echo "abort" >testfifo, but the program cannot display ABORT, it still displays Nothing every 5 seconds.
Please help!!