如何与 clisp 中的 ssh 会话交互?
我想使用 common lisp 来编写脚本,并通过 ssh 连接到远程计算机并发送一些命令。最简单的方法似乎是使用 clisp 的 ext:run-shell-command,文档此处,以及然后读取并写入结果流。如果有更好的方法请告诉我。当我尝试这样做时:
[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.
inferior-lisp-buffer 中的进程挂起,必须使用 Cc c 终止。然而, shell-str 对象确实被创建了,但是当我尝试从中读取时,那里没有输出。
[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
使用“ls -l”之类的命令运行 ext:run-shell-command 确实可以按预期工作。在 cygwin 甚至 Windows 命令提示符中运行 ssh 可以正常工作。我在 Windows 7 上运行 clisp 2.49 和 openssh 5.9p1。
编辑:通过不使用密码和 ssh 的双 -t 参数来使其工作。
(setf str (ext:run-program "ssh" :arguments '("-t" "-t" "host") :output :stream :input :stream))
(format str "ls -l~%")
(finish-output str)
(read-line str)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Snowape 找到了 clisp 的解决方案。下面是该 CCL 解决方案的工作版本:
作为一种替代方法,您可以使用 Quicklisp 加载 Trivial Shell 包,然后从执行脚本的 lisp 会话中启动一个 shell 进程(其中将包含 ssh 命令) 。不过,我从未在 Windows 中尝试过 Trivial Shell,所以不确定它的表现如何。
Snowape found a solution for clisp. Here's a working version of that solution for CCL:
As an alternative approach, you could load up the Trivial Shell package using Quicklisp, and then launch a shell process from within the lisp session that does the scripting (would have the ssh command within it). I've never tried Trivial Shell within Windows though, so not sure how that would behave.