Expect: how to print every output of a spawned process to the user

走远了吗. 提交于 2019-12-11 03:22:24

问题


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

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