在生成的rsync进程上使用wait会在期望

时间:2016-04-24 14:34:43

标签: crash wait expect rsync

我有一个简单的expect脚本,它启动rsync进程并发送密码。之后我使用wait来捕获rsync进程的结果代码:

#!/usr/bin/expect

# check arguments
if { $argc != 3 } {
    puts "Usage $argv0 src dest password"
    exit 1
}

# set arguments
set src [lindex $argv 0]
set dest [lindex $argv 1]
set password [lindex $argv 2]

# call rsync
spawn rsync --delete --exclude=.svn  -rvae ssh $src $dest

# confirm connect question
set timeout 2
expect {
    *connecting* {send "yes\r"}
}

# send password
set timeout 5
expect {
    *assword: {send "$password\r"}
}

# invalid password
set timeout 2
expect {
    *denied* {exit 2}
}

# get process result
lassign [wait] pid spawnid os_error_flag value

# exit with error code
exit $value

问题是我看到密码提示2秒后(可能在"无效密码"块超时后)rsync崩溃。它只是停止传输,甚至Ctrl-C也不能再杀了。调试证明wait命令导致此行为。在我使用之前

set timeout -1
expect eof

一切正常。但是这样我就无法检索rsync的结果代码。

我的expect脚本中是否存在问题,或者这是wait命令或rsync中的错误?

1 个答案:

答案 0 :(得分:1)

wait之后你可以expect eof。例如:

% cat foo.exp
spawn sh -c "exit 17"
expect eof
set waitResult [wait]
send_user $waitResult\n
% expect foo.exp
spawn sh -c exit 17
29293 exp7 0 17
%
相关问题