Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 5 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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