我想使用 common lisp 编写脚本,并通过 ssh 连接到远程计算机并发送一些命令。最简单的方法似乎是使用 clisp 的 ext:run-shell-command, documentation here,然后读取和写入结果流。如果有更好的方法让我知道。当我尝试这个时:
[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.
劣质 lisp 缓冲区中的进程挂起,必须用 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)