0

I have a program, that runs on only one Raspberry Pi, but could be run from multiple other computers (through SSH). When I run my program on the Pi, it runs as expected. To be able to run from crontab or SSH, I created (ok, scissored together) some bash scripts, however, it is not running as intended. The first was like this:

exec sudo /usr/bin/java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/home/pi/forgokapu/dist/forgokapu.jar' < /dev/tty1

However, it did not allow to read from the Pi's tty1. (I think that & means to run in the background.) However, even without the &, it gives the output to the computer it's run from (pts/0), but doesn't take input from anywhere. I tried to add

exec sudo /usr/bin/java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/home/pi/forgokapu/dist/forgokapu.jar' < /dev/tty1 >/dev/tty1

to force both input and output to the tty1, but now the output does not appear anywhere, and ps -A shows it is running on pts/0, not tty1.

The < /dev/tty1 is inside the script, but the program still runs on pts/0 (or crontab), and not taking input from it's tty1. Bash does.

520 tty1 00:00:00 login 690 tty1 00:00:01 bash 917 pts/0 00:00:00 bash 1221 pts/0 00:00:00 sudo 1227 pts/0 00:00:00 java 1241 pts/0 00:00:00 ps

Question:

How can I force the program to take input from the tty1? I don't need bash, so it should run in the foreground. Redirection of output is not important, but I would have from the origin of the program start for debugging purposes.

I also tried 0</dev/tty1, but the input is still from pts/0

I also tried

setsid sh -c 'exec sudo /usr/bin/java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar "/home/pi/forgokapu/dist/forgokapu.jar" <> /dev/tty1 >&0 2>&1'

from Start a process on a different tty , but it's still not working. :'(

script is also no good, I need the opposite of what it does.

  • was one of the attempts: program < /dev/tty1 ? That's the simplest, unless the program is deciding for itself what to open? – Jeff Schaller Feb 11 at 13:17
  • Bash should decide. The < /dev/tty1 is inside the script, but the program still runs on pts/0 (or crontab), and not taking input from it's tty1. Bash does. 520 tty1 00:00:00 login 690 tty1 00:00:01 bash 917 pts/0 00:00:00 bash 1221 pts/0 00:00:00 sudo 1227 pts/0 00:00:00 java 1241 pts/0 00:00:00 ps </dev/tty1 does not redirect java to tty1. :( – kry Feb 11 at 13:20
  • You'll need to edit the post to provide clarification -- particularly ones that include formatting (comment formatting is limited). – Jeff Schaller Feb 11 at 13:37
  • Just to check: you're not actually using those parenthesis around the command, are you? Because they are shell syntax for a subshell, and at that point of the command, it'd be invalid syntax. I do also wonder what the meaning of exec ... & is, since exec replaces the shell, so it can't very well be put in the background – ilkkachu Feb 11 at 13:39
  • No, it just copies a lot of things in the background, so I snipped the actual command. I don't know what & does, I just copied it from an another question. It does not affect the behavior of the Pi, does the same with and without. – kry Feb 11 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.