使用 nc 連接 socket 端,就會一直咬在那邊,但是想要命令執行完成就結束,該怎麼做呢?
nc 如何 STDIN 結束就關閉
nc 可以靠下述兩個參數來達成:
- -q seconds after EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever.
- -w secs timeout for connects and final net reads
範例
- echo "test" | nc -q 1 localhost 11211
- echo "test" | nc -w 3 localhost 11211