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

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!


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

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

You must log in to answer this question.

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