How to capture expect output using spawn and sftp under solaris

走远了吗. 提交于 2019-12-12 04:35:59

问题


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

This works just fine.

My specific question is how to I capture the results of the send "ls -l\r" command in a file.


回答1:


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/



来源:https://stackoverflow.com/questions/12220447/how-to-capture-expect-output-using-spawn-and-sftp-under-solaris

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!