0
我试图打开与TCL8.5脚本的东西,如SSH连接:开放ssh连接冻结
catch {set fh [open "|sshpass -p $password ssh [email protected]$ip" w+]} catch_output
if {[info exists fh] != 1} {
puts "err - $catch_output"
return 0
}
fconfigure $fh -buffering none -blocking 0
set i 0
while {1} {
puts "iteration $i."
set data [read -nonewline $fh]
append input_sum $data
puts -nonewline $data
after 1000
incr i
}
但只有文字,我从远程计算机得到的是:
Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.5.0-45-generic i686)
* Documentation: https://help.ubuntu.com/
这是它挂起的地方... 变量$i
有助于确保代码正在运行。
我已经确认没有EOF命令eof $fh
。
当我手动执行此,我得到(密码,用户& IP地址都是虚构的):
$ sshpass -p abcdef ssh [email protected]
Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.5.0-45-generic i686)
* Documentation: https://help.ubuntu.com/
Last login: Thu Apr 3 11:22:33 2014 from 5.6.7.8
[email protected]:~#
请注意:我知道有其他的方法来执行这一(期望,键),但我必须明白为什么这个特定的方法不起作用。谢谢。
行缓冲时输出不会到终端? –
@DonalFellows:对不起,但不明白这个问题。 – Dor
_Many_程序在输出到管道或文件而不是终端时更改其缓冲样式。我不知道这里是否属实。 (如果你只是运行一个远程命令,你可能不需要关心。) –