【问题标题】:How to capture expect output using spawn and sftp under solaris如何在 solaris 下使用 spawn 和 sftp 捕获期望输出
【发布时间】:2012-08-31 18:02:36
【问题描述】:

我正在使用 expect 来生成一个 sftp 会话,如下所示:

(为了清楚起见,剪掉了很多代码,是的,我理解其中的风险......)

#!/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

这很好用。

我的具体问题是如何在文件中捕获 send "ls -l\r" 命令的结果。

【问题讨论】:

    标签: shell unix solaris expect


    【解决方案1】:

    在你send "ls\r" 之后,你应该expect 一些东西。在expect 语句之后,变量$expect_out(0,string) 将包含您想要的输出。你必须解析出实际的命令字符串和随后的提示。你可以在http://docs.activestate.com/activetcl/8.5/expect4win/找到一些例子

    【讨论】:

      猜你喜欢
      • 2021-04-05
      • 2012-10-23
      • 1970-01-01
      • 2013-07-14
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多