Send String over netcat connection

I have two virtual machines open, one is listening on the connection, the other connects with nc <ip> <port> from a python subprocess call. I want to send just 1 line of text over the connection then close it. I know how to send a file cat cat <file> | nc <ip> <port> but how can I just send a line of text in the nc command (without using files)?


  • Try this:

    echo -n 'Line of text' | nc <ip> <port>

    You can also use temp file syntax:

    cat <(echo "Line of test") | nc <ip> <port>