I'm trying to send commands to a tcp port using netcat
and pipe response
when I run netcat
and type my command it prints response correctly but when I pass command from a pipe it sends the command correctly but doesn't print response
So, this works correctly:
netcat localhost 9009
while this just sends command but doesn't print response:
echo 'my_command' | netcat localhost 9009
why?
How can I make netcat
to print response text ?
Best Answer
As @Patrick said, this problem is usually due to
netcat
exiting before the response has been given. You remedy that by adding-q 2
to the command line, i.e., tellnetcat
to hang around 2 seconds after detecting EOF on standard input. Obviously you can make it wait some other number of seconds as well.