我已经花了一整天的时间在到处搜索答案,但目前还没有找到有效的方法。我的目标是运行一个expect脚本,以附加到GNU screen会话,发送命令行参数(一个命令),并输出该命令的结果。下面是我的其中一个脚本:
#!/usr/bin/expect -f
set timeout 3
#exp_internal 1
spawn screen -raAd call_sess
sleep 1
expect -re "\\\$" {
send $argv
send "\n"
sleep 1
}
expect -re ".*" {
set output $expect_out(0,string)
}
expect "\$" {
send "\001"
send "d"
}
expect eof {
puts "OUTPUT---------------"
puts $output
puts "OUTPUT---------------"
}
$expect_out(0,string) 仅匹配换行符,虽然 .* 应该匹配自上次匹配以来的所有内容。如果有人能帮我解决这个问题,那就太好了,我几乎要放弃并认为它是不可能的。
编辑:在评论中已经解答,但我应该指出命令确实在屏幕中运行,我只是无法正确获取输出。
编辑2:根据建议将脚本更改为生成屏幕,谢谢!