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.

Quick question that has been haunting me all day.. I have a bash script that includes this line:

nc -l 8044 | tee nc-output &

The output from netcat is never being written to nc-output. If I run that line outside of the bash script, it works.

nc -l 8044 > afile &

Also does not work, but works outside a bash script.

I need the ampersand there so I can run the process separately and continuing executing my batch script. Any suggestions would be great!

Thanks!

share|improve this question
    
One thing that comes to mind: does your script have a different working directory than you expect? –  mboldt Jun 19 '12 at 17:02
    
I don't think that is the problem. The script is creating an empty file on each run.. just nothing written to it. –  Gregorio Di Stefano Jun 19 '12 at 17:04
add comment

1 Answer

The problem is that as soon as nc accepts a connection it will try to read from stdin. When you run this as a bash script it will always read EOF immediately and close the connection, what doesn't happen when you run it outside a script.

Use -d switch to prevent nc from read from stdin.

nc -d -l 8044 > afile &
share|improve this answer
    
I will give this a try get back to you! Thanks! –  Gregorio Di Stefano Jun 19 '12 at 17:35
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.