Using netcat/cat in a background shell script (How to avoid Stopped (tty input)? ) Using netcat/cat in a background shell script (How to avoid Stopped (tty input)? ) shell shell

Using netcat/cat in a background shell script (How to avoid Stopped (tty input)? )


you probably want netcat's "-d" option, which tells it not to read from STDIN.


I can confirm that -d will help netcat run in the background.

I was seeing the same issue with:

nc -ulk 60001 | nc -lk 60002 &

Every time I queried the jobs, the pipe input would stop.

Changing the command to the following fixed it:

nc -ulkd 60001 | nc -lk 60002 &


Are you sure you've given your script as is or did you just type in a rough facsimile meant to illustrate the general idea? The script in your question has many errors which should prevent it from ever running correctly, which makes me wonder.

  1. The spaces around the = in catpid=$! make the line not a valid variable assignment. If that was in your original script I am surprised you were not getting any errors.

  2. The kill catpid line should fail because the literal word catpid is not a valid job id. You probably want kill "$catpid".

As for your actual question:

  • cat should be reading from /dev/charfile and not from stdin or anywhere else. Are you sure it was attempting to read tty input?

  • Have you tried redirecting netcat's input like netcat < /dev/null if you don't need netcat to read anything?