问题
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?
Thanks
回答1:
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"
来源:https://stackoverflow.com/questions/7105629/expect-how-to-print-every-output-of-a-spawned-process-to-the-user