In my Ubuntu, i run java application in background. I use bash script to run it and now it looks like:

nohup java -jar app.jar &
exit 0

The problem that i want to be able to write an input string to my application, without making it foreground, from different terminals/sessions. Something like

echo "mytext" > /appdir/in

How should i change my script?



set -e

if [ ! -p in ]; then
    mkfifo in
tail -f in | java -jar app.jar

Send command to the application with following syntax

echo "command" > /home/user/in
  • 1
    This is good solution, but I do not get how to get stdout from the app. – loretoparisi Jun 30 '17 at 15:21

Give this a try:

mkfifo /appdir/in
nohup java -jar app.jar < /appdir/in &
exit 0

The test:

$ ./startapp.sh
$ printf "%s\n" "mytext" >> /appdir/in
$ cat nohup.out


There is additional control to add in order to manage the lifecycle of the /appdir/in named pipe.

  • Good try but it does not work (with or without nohup). My application simply not running (not started). – Croll Mar 31 '16 at 11:48
  • @DmitrjA So the application start needs to be troubleshooted? The test section here is a real test. Do you have any error message on the console, in the appilcation log file, in nohup.out? My own app.java read line from STDIN and write it to STDOUT. – Jay jargot Mar 31 '16 at 11:50
  • If i run java -jar app.jar < pipe.in java is not started, and terminal hangs untill Ctrl+Z or Ctrl+C – Croll Mar 31 '16 at 11:56
  • try java -jar app.jar < pipe.in & instead – Jay jargot Mar 31 '16 at 12:00
  • Its same, but without hanging. I don't have application sources, but it's normal command line tool. Tried to use "/proc/PID/fd/0", no success, but i could use it incorrectly. – Croll Mar 31 '16 at 12:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.