Expect: how to print every output of a spawned pro

2019-07-10 08:31发布

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

标签: tcl expect
1条回答
别忘想泡老子
2楼-- · 2019-07-10 09:24

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"
查看更多
登录 后发表回答