0

I am using the following to send and receive from a TCP socket:

exec 3<>/dev/tcp/localhost/port
echo -e "textcommand\r" >&3
cat <&3
exec 3<&-;exec 3>&-

The cat <&3 line displays the response from the localhost in the terminal, but I have to use Ctrl+d or Ctrl+c to return to the command line. How can I print the response from localhost and return to the command line without any keyboard interaction?

EDIT

(echo -en "textcommand\r"; sleep 1) | telnet localhost port

The above works as an alternative. Found this here: https://stackoverflow.com/a/24204924/5900282

EDIT 2

There was a similar issue here: Capturing data from a Fluke 1620a via Bash /dev/tcp file descriptor

0

1 Answer 1

0

Use timeout:

exec 3<>/dev/tcp/localhost/port
echo -e "textcommand\r" >&3
timeout 0.2 cat <&3
exec 3<&-; exec 3>&-

You must log in to answer this question.

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