Expect_out help!!!

I am trying to read a file via SSH connect and store it to expect_out(buffer). I am a virgin to expect. Help is really appreciated. Wasted almost a day :frowning:

Code is as follows

expect "system32>"
send "type output.csv";
send "\r";
expect "system32>"
set outcome $expect_out(buffer)
puts "I am here $outcome\n"

but outcome doesn't return me anything :frowning:

Here's an example of the way that I've done it in the past. Hope this helps.

#!/usr/bin/expect -f
#
# example of executing a command with expect
# and retrieving an exit\return code
#

# set credentials
set u ""
set p ""

# set hostname
set h ""

# set command to run
set cmd "CMD 2>/dev/null"

# capture the return code from the command
set retval "echo 'Return Code: '$?"

# spawn the ssh connection, run the command,
# and retrieve the return code
spawn ssh $u@$h "$cmd;$retval"
expect "?assword*"
send -- "$p\r"
send -- "\r"
expect -re {Return Code: (\d+)}
set retval $expect_out(1,string)
expect eof

# process the return code
if {$retval != 0} {
    puts stderr "Fail"
} else {
    puts stderr "Pass"
}

7a8b1a878d0ef333911b000d7c6858c8

Thank You in2nix4life :slight_smile:

I tried

" $expect_out(1,string)" and " $expect_out(0,string)"
but didn't return what I expected.

instead I use "$expect_out(buffer)" with "match_max 10000" which return me what I was expecting.

Just wondering is it because the output i am trying to capture is too long which make " $expect_out(0,string)" fail?