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

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



Solution 1:[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"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1