artyom-poptsov / guile-ssh

Guile-SSH is a library that provides access to the SSH protocol for GNU Guile programs.
https://memory-heap.org/~avp/projects/guile-ssh
GNU General Public License v3.0
65 stars 13 forks source link

Documentation for open-remote-pipe* is misleading #39

Closed graywolf closed 3 months ago

graywolf commented 7 months ago

The documentation claims

 -- Scheme Procedure: open-remote-pipe* session mode prog [args...]
     Execute PROG on the remote host with the given ARGS using a SESSION
     with a pipe to it.  Returns newly created channel port with the
     specified MODE.

However what is actually executed is the equivalent of (string-append prog " " (string-join args " ")). That is quite surprising, given the signature of the procedure, so I believe it should be documented.

Working around it (and getting actual equivalent of open-pipe*) is not hard, but one has to know it is necessary and I find that somewhat hard to figure out from the current documentation.

artyom-poptsov commented 7 months ago

Hello!

Yes, currently open-remote-pipe* literally does this:

(open-remote-pipe session (string-join (cons prog args)) mode)

It's not clear for me what do you expect from the procedure. Could you please share your workaround? Maybe that way I can better understand how to fix the documentation (or the procedure itself, for that matter.)

Thanks, -avp

graywolf commented 7 months ago

Hi :)

It's not clear for me what do you expect from the procedure. Could you please share your workaround?

Sure, I would have expected (open-remote-pipe* "ls" "-la" "/foo bar") to list details about a file /foo bar, the same way local (open-pipe* "ls" "-la" "/foo bar") would.

My workaround is:

(define (shell-quote s)
  "Quote string S for sh-compatible shells."
  (string-append "'" (string-replace-substring s "'" "'\\''") "'"))

(apply open-remote-pipe* session OPEN_BOTH
                     (shell-quote prog) (map shell-quote args))

That seems to do what I need, as long as there is POSIX-compatible shell on the other end.

artyom-poptsov commented 3 months ago

Hello!

I pushed changes that address this issue as 7a6c86fb4597abd03f96f32ca1fc07a16e6831b7

Please check if it works for you.

Thanks, -avp

graywolf commented 3 months ago

Can confirm the commit does work, thank you :)