I'm making a kiosk like system, which reads data from a barcode reader, and a java program reads it from the console, and interprets it. I switched on autologin, and use crontab to run it like
* * * * * /home/name/script.sh < /dev/tty1 > /dev/tty1
while the script itself also includes
exec sudo /usr/bin/java -jar '/home/name/reader/dist/reader.jar' </dev/tty1
(There are other parts of the script, but they just check other running programs...)
What I expect is that after login, the crontab runs it like I was simply running it from the console. However, results are pretty whacky.
Sometimes it runs correctly for a while. However, after a few reads, bash comes in, and starts interpreting the tty1 input, instead redirecting it to java.
Sometimes it shows it's running, but never sends any information to the java.
Sometimes after receiving a kill command, the crontab restarts it without redirecting the input to java.
In the meantime, it communicates with other computers, which also send commands. Things like it's trying to update, responses, checks if everything is still running, and they are redirected to the tty1 output, but these always appear correctly, even when bash is reading from the stdin.
While I actually have no use for bash (I control it from SSH), it communicates with the other computers via ttyS0 and ttyAMA0, so they should not be locked.
I also tried running java as a service, but in that case, it constantly read 'null's from the input, making it impossible to extract any useful data from it.
Now I'm thinking it should be
0< /dev/tty1 instead, but other tutorials and questions are damn vague about input redirecting. There are tons about redirecting output and input from file, but nothing about input from tty...
Got a solution, yay! Start a process on a different tty