How can I interact with an ssh session in clisp?
-
29-10-2019 - |
Вопрос
I want to use common lisp for scripting, and connecting to a remote computer over ssh and sending some commands. The easiest way seems to be to use clisp's ext:run-shell-command, documentation here, and then read from and write to resulting stream. If there is a better way let me know. When I try this:
[5]> (setf shell-str (ext:run-shell-command "ssh remotecomp" :input :stream :output :stream))
#<IO TWO-WAY-STREAM #<INPUT BUFFERED PIPE-INPUT-STREAM CHARACTER 1204> #<OUTPUT BUFFERED PIPE-OUTPUT-STREAM CHARACTER 1204>>
[6]> Pseudo-terminal will not be allocated because stdin is not a terminal.
The process in the inferior-lisp-buffer hangs and has to be killed with C-c c. However the shell-str object does get created, but when I try to read from it there is no output there.
[9]> (read-line shell-str)
*** - READ: input stream
#<IO TWO-WAY-STREAM #<INPUT BUFFERED PIPE-INPUT-STREAM CHARACTER 1204>
#<OUTPUT BUFFERED PIPE-OUTPUT-STREAM CHARACTER 1204>>
has reached its end
The following restarts are available:
ABORT :R1 Abort main loop
Running ext:run-shell-command with something like "ls -l" does work as expected. Running ssh in cygwin or even windows command prompt works as it should. I'm running clisp 2.49 and openssh 5.9p1 on windows 7.
Edit: Got it working by using no passwords and double -t arguments to ssh.
(setf str (ext:run-program "ssh" :arguments '("-t" "-t" "host") :output :stream :input :stream))
(format str "ls -l~%")
(finish-output str)
(read-line str)
Нет правильного решения