Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Linux (which)? Unix (which)? OS X? AmigaOS? It probably wouldn't hurt to say which shell. Bash? Bourne? Korn? C? Z? Fish? – Dennis Williamson Dec 21 '10 at 18:45
Sorry about that. Updated the question. – vivin Dec 21 '10 at 18:54
up vote 6 down vote accepted

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
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.)

share|improve this answer
Thanks a bunch! This is really helpful! – vivin Dec 21 '10 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .