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

version v1.0.0-alpha have problems when parsing the args #2

Closed alkorsan closed 6 years ago

alkorsan commented 6 years ago

Hi, First I want to thank you for this gem. thank you very much.

The new version v1.0.0-alpha can't parse the args well, the old version 0.4 works well!. I m using cygwin in windows 7.

using this exemple : https://stackoverflow.com/questions/48912184/wscat-commands-from-script-how-to-pass/48914019#48914019

#!/usr/bin/env bash

runscript() {
  commands=( "first command" "second command" "third command" )

  for command in "${commands[@]}"; do
    echo "Writing command to server" >&2
    echo "$command"
    echo "Reading response from server (assuming exactly one line)" >&2
    read -r line
    echo "Received response: $line" >&2
  done

  # kill websocat, even if the websocket doesn't get closed
  kill "$PPID"
}

export -f runscript

the new version gaves this error

$ ./websocat_nossl_1.0_i686-pc-windows-gnu.exe ws://echo.websocket.org sh-c:'exec bash -c runscript'
'exec' is not recognized as an internal or external command,
operable program or batch file.

using the old version 0.4 everything works fine:

$ ./websocat_nossl_0.4_i686-pc-windows-gnu.exe ws://echo.websocket.org sh-c:'exec bash -c runscript'
INFO:websocat: Connecting to ws://echo.websocket.org/
INFO:websocat: Validating response...
INFO:websocat: Successfully connected
Writing command to server
Reading response from server (assuming exactly one line)
Received response: first command
Writing command to server
Reading response from server (assuming exactly one line)
Received response: second command
Writing command to server
Reading response from server (assuming exactly one line)
Received response: third command
environment: line 9: kill: (1) - No such process
The pipe is being closed. (os error 232)

the version 0.5 too have problems, but seems a different error:

$ ./websocat-0.5.1--windows.exe ws://echo.websocket.org sh-c:'exec bash -c runscript'
websocat: WebSocketError: WebSocket URL failure

thank you.

alkorsan commented 6 years ago

I think it is not a bug, when I remove exec in sh-c:"exec bash -c runscript" the version 1.0 works well

$ ./websocat_nossl_1.0_i686-pc-windows-gnu.exe ws://echo.websocket.org sh-c:"bash -c runscript"
Writing command to server
Reading response from server (assuming exactly one line)
Received response: first command
Writing command to server
Reading response from server (assuming exactly one line)
Received response: second command
Writing command to server
Reading response from server (assuming exactly one line)
Received response: third command
environment: line 9: kill: (1) - No such process

so I don't know what to say :)

vi commented 6 years ago

Note that 1.0.0-alpha has a bug in exec/sh-c specifier: if the executed program exits prematurely, it starts busy looping and draining memory.

The fix is in already master.

Also note that exec: with arguments is now supported, unlike in 0.4.

./websocat_....exe ws://echo.websocket.org exec:bash --exec-args -c runscript
vi commented 6 years ago

sh-c (an alias of cmd:) now uses cmd.exe on Windows instead of just calling sh unconditionally.

Do you think locking sh-c: to sh (and making only cmd: choose the shell based on OS) is a good idea?

alkorsan commented 6 years ago

Thank you. To answer your question I need to understand this: 1-cmd: is not working in 0.4 and 1.0 , only sh-c: works in cygwin, so I m not sure if it is an alias or something else...

$ ./websocat_nossl_1.0_i686-pc-windows-gnu.exe ws://echo.websocket.org cmd:'bash -c runscript'
ERROR 2018-06-20T00:23:50Z: websocat::specparse: Invalid specifier string `cmd:bash -c runscript`
websocat: Wrong specifier

2- why do we have exec: --exec-args and sh-c: ? they seems to do the same thing!, and we already can use exec:cmd so why a new cmd:?

vi commented 6 years ago

exec: allows to specify array of command-line arguments without escaping level (probably unrelevant on Windows) and allows to launch the program directly without going though shell like sh.

vi commented 6 years ago

cmd: is not working in 0.4 and 1.0

Because of it's in post-1.0.0-alpha master. I starting to forget what was in 1.0.0-alpha and what is already fixed in master.

Maybe time to make a 1.0.0-beta?

alkorsan commented 6 years ago

and allows to launch the program directly

then exec is superior than sh-c: / cmd: , because we can chose a shell if needed or run the command directly. then can I say that sh-c: / cmd: is useless now?

I starting to forget what was in 1.0.0-alpha and what is already fixed in master.

I will attempt to compile from the master repository to see if cmd: works, if I can . I never used Rust before.

vi commented 6 years ago

then can I say that sh-c: / cmd: is useless now?

It is often more convenient. See embedded examples on README or the long help message.

attempt to compile from the master repository

1.0.0-beta is in progress of being built. Wait for half an hour and I'll publish it.

vi commented 6 years ago

https://github.com/vi/websocat/releases/tag/v1.0.0-beta

Note that this sh-c: vs cmd: semantic is about to change.

alkorsan commented 6 years ago

Now with this update cmd: works fine like sh-c:. they seems identical, they both call cmd.exe.

So I think making only cmd: choose the shell based on OS is better, but in fact for me I prefer exec: because I can choose the shell and I still don t see any benefit in using cmd:/sh-c:

thank you

alkorsan commented 6 years ago

So I think making only cmd: choose the shell based on OS is better

because if we are in cygwin/bash shell then we don t need cmd.exe , and if we are in cmd.exe shell and don t have bash.exe then we need to run cmd.exe obligatory.

and having sh-c: run cmd.exe is useless , we never need cmd in cygwin/bash world thanks to God :)

vi commented 6 years ago

I still don t see any benefit in using cmd:

Simply less typing / concise command lines. Compare

websocat -E - exec:/bin/sh --exec-args -c 'for i in `seq 0 4`; do echo $i; done'

and

websocat -E - cmd:'for i in `seq 0 4`; do echo $i; done'