I found a similar question here but there's no answer.
I wrote this script named answer.sh:
#!/bin/sh
echo "HTTP/1.1 200 OK
Hello World"
If I run
./answer.sh | nc -c -l -p 8797
and then browse to localhost:8797 I get a web page with only a "Hello World" text (that's exactly what I want).
but if i run
nc -l -p 8797 -e ./answer.sh
the browser says the connection was interrupted. So I try
nc localhost 8797
to see what happens and I get this:
HTTP/1.1 200 OK
Hello World
read(net): Connection reset by peer
I would like to understand what's going on and what are (technically) the difference between the working way and the other.
Thanks in advance.