#52 netcat still needs an input stream when receiving TCP data

open
nobody
5
2011-03-20
2011-03-20
Anonymous
No

When running netcat in the background from a script, any attempt to connect will kill it.

Example script:
#!/bin/sh
nc -l 1337 &

When you run this, and then run:
nc localhost 1337

The original instance dies immediately, with no indication for why. However, if we do:

#!/bin/sh
tail -f /dev/null | nc -l 1337 &

Then connecting to port 1337 will work correctly, and you can see the output being echoed on the terminal.

Discussion