vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
7.18k stars 278 forks source link

how to terminate exec process? #196

Open k0xxxx opened 1 year ago

k0xxxx commented 1 year ago

Hello dear Vi! I use websocat -E ws-l:127.0.0.1:8080 exec:"cmd" I connect to a websocket using a browser and run the program from the command line echo {"method":"SUBSCRIBE","params":["test"],"id":100} | websocat -n wss:/server.com/ws | php script.php argv1 argv2. It can run indefinitely. How can I interrupt (terminate) the execution of the program from the browser? I tried sending "^C" but it doesn't work in windows.

vi commented 1 year ago

Try newly added option --exec-exit-on-disconnect from 734cc58e7c27e608909eee3c0596289b2a3e414b.

k0xxxx commented 1 year ago

Dear Vi. In OS Windows 10 it option "--exec-exit-on-disconnect" is work. After connect to ws on port 8080, i close my web browser and i see this message on windows cmd terminal D:\D\OpenServer\modules\php\PHP_7.4>websocat -t --exec-exit-on-disconnect -E ws-l:127.0.0.1:8080 exec:cmd websocat: other error websocat: error running and created php.exe process is terminated. But when I tried to show the same in Ubuntu, ./websocat -t -E --exec-exit-on-disconnect -v ws-l:1.2.3.4:9000 exec:sh the php.exe process still running in the background.

UPDATE this bug stay while my php script do not send any echo "message"; to the terminal console

vi commented 1 year ago

I tried websocat -t -E --exec-exit-on-disconnect -v ws-l:127.0.0.1:9000 cmd:'ping 127.0.0.1' with and without --exec-exit-on-disconnect. With the option, it does terminate process even on Linux, but does not free up the PID (i.e. leaves a zombie).

Until this is fixed, you may want to use --exec-sighup-on-stdin-close on Linux.