Redirect process stdin and stdout to netcat

前端 未结 3 2228
清酒与你
清酒与你 2021-02-10 09:43

I have an embedded linux application with a simple interactive command line interface.

I\'d like to access the command line from telnet (or network, in general).

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 10:26

    Is there a way to redirect both stdin and stdout to netcat

    There is socat, which is a more advanced netcat. You can redirect both stdin and stdout with it. E.g.:

    socat TCP4-LISTEN:5556,reuseaddr,fork EXEC:"cat - /etc/redhat-release"
    

    In the above cat reads stdin and /etc/redhat-release and outputs them into stdout.

    And then try using that:

    $ echo "hello" | nc 127.0.0.1 5556
    hello
    Fedora release 22 (Twenty Two)
    
    $ echo "hello 2" | nc 127.0.0.1 5556
    hello 2
    Fedora release 22 (Twenty Two)
    

提交回复
热议问题