Pipe/send command to process running on nohup that accepts input from STDIN

nohuppipe

I have a program that I run using nohup program &. This program accepts input from STDIN. Is there any way to send text to the STDIN of a program that is running via nohup?

This is on FreeBSD running bash. I would like to see how this is done on linux as well.

Best Answer

nohup runs the program with standard input redirected from /dev/null (assuming that you didn't redirect the nohup command itself). So no, you can't send input to this program.

If you want to send input to the program, redirect the input when you start it:

nohup program <input-file.txt &  # input from a file
nohup data-producer | nohup program &  # input from another program
mkfifo program.pipe; nohup program <program.pipe &  # input from a named pipe, feed it what you want later

(Actually, it may be possible to reconnect the program's standard input to another source, by using ptrace, i.e. a debugger or other hack. This could crash the program if it keeps track where its input is from. See How can I pause up a running process over ssh, disown it, associate it to a new screen shell and unpause it?; there are other questions on the SE network on this topic.)

Related Question