I've spent the better part of the day now searching everywhere for an answer, and nothing has worked so far. What I'm trying to do is run an expect script that will attach to a GNU screen session, send it the command line arguments (a command), and output the result of that one command. So far this is one of my scritps:
#!/usr/bin/expect -f
set timeout 3
#exp_internal 1
spawn screen -raAd call_sess
sleep 1
expect -re "\\\$" {
send $argv
send "\n"
sleep 1
}
expect -re ".*" {
set output $expect_out(0,string)
}
expect "\$" {
send "\001"
send "d"
}
expect eof {
puts "OUTPUT---------------"
puts $output
puts "OUTPUT---------------"
}
And $expect_out(0,string) only matches a newline, even though .* should match everything since the last match. If anyone could help me get this working that would be awesome, I'm about ready to give up and call it impossible.
EDIT: Answered in the comments, but I should have specified that the command does get run in the screen, I just can't capture the output correctly.
EDIT2: Changed the script to spawn screen as suggested, thanks!
The easy part of the answer is that .* is matching the empty string, so that's going into expect_out.
The hard part is that screen will give you the whole screen - including any previous commands -, so just finding the output of the command you sent might be a little difficult.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With