期望:如何将生成的过程的每个输出打印给用户 [英] Expect: how to print every output of a spawned process to the user
本文介绍了期望:如何将生成的过程的每个输出打印给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写期望脚本,部分命令将以其他用户身份执行.所以我需要产生一个kuu进程,然后在用户提供密码后将命令发送给它.但是,我如何收集这些命令的输出并将其输出给运行期望脚本的用户呢?
I'm trying to write an expect script, part of the commands will be executed as a different user. So i need to spawn an kuu process, then send commands to it after user provided password. But how do I collect the output of those commands and print it to the user who is running the expect scripts?
谢谢
推荐答案
可以使用以下方法完成此操作:
This can be done by using something like the following:
proc outputUntilPrompt {} {
global expect_out
set prompt "ACT:*>*"
set output ""
while 1 {
expect {
-re "(\[^\r]*\)\r\n" {
append output $expect_out(buffer)
}
$prompt {
append output $expect_out(buffer)
break
}
}
}
return $output
}
send_user "$output"
这篇关于期望:如何将生成的过程的每个输出打印给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文