I am trying to run a java console app in Raspbian rc.local.
It is a boot menu to select a menu item based on a keyboard input. The program runs fine, if running at command prompt.
However, when starting the java console app within rc.local
java -jar /home/pi/RaspPiStartup/RaspPiStartup.jar
the application is not able to read keyboard inputs.
Scanner in = new Scanner(System.in);
Console con=System.console();
AtomicInteger num=new AtomicInteger(-1);
Thread thread = new Thread() {
public void run() {
try {
int i1;
if (con==null) {
System.out.println("KeyScan In");
i1=in.nextInt();
System.out.println("KeyScan "+i1);
}
else {
System.out.println("KeyCon In");
i1=Integer.parseInt(con.readLine());
System.out.println("KeyCon "+i1);
}
num.set(i1 );
}
catch(Exception e) {
System.out.println("Fehler Keyboard In"+e.toString());
}
}
};
thread.start();
I tried several ways, as you see. This solution gives me an Exception. As con == null in rc.local, the scanner tries to read. Thus resulting in an java.util.NoSuchElementException.
What do I need to do, to read a keyboard input in rc.local? Thanks...