如何在solaris下使用spawn和sftp捕获期望输出 [英] How to capture expect output using spawn and sftp under solaris
问题描述
我正在使用Expect生成一个sftp会话,如下所示:
I am using expect to spawn a sftp session as follows:
(为了清晰起见,大量的代码被剪掉了,是的,我理解其中的风险...)
(lots of code snipped for clarity, and yes I understand the risks...)
#!/opt/csw/bin/expect -f
<snip>
spawn sftp $user@$host
set rez [connect $passw]
if { $rez == 0 } {
send "cd $location\r"
set timeout -1
send "ls -l\r"
send "quit\r"
expect eof
exit 0
}
puts "\nError connecting to server: $host, user: $user and password: $passw!\n"
exit 1
这很好用.
我的具体问题是如何捕获文件中发送"ls -l \ r" 命令的结果.
My specific question is how to I capture the results of the send "ls -l\r" command in a file.
推荐答案
send "ls\r"
之后,您应该expect
一些东西.在expect
语句之后,变量$expect_out(0,string)
将包含所需的输出.您必须解析出实际的命令字符串和随后的提示..您将可以在 http://docs.activestate.com/activetcl/8.5/expect4win/
After you send "ls\r"
you should expect
something. After the expect
statement, the variable $expect_out(0,string)
will contain the output you want. You do have to parse out the actual command string and the subsequent prompt.. You'll be able to find some examples at http://docs.activestate.com/activetcl/8.5/expect4win/
这篇关于如何在solaris下使用spawn和sftp捕获期望输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!