= Get output of `send` command on expect
This pattern works well:
``
set prompt ">>> "
log_user 0
send "What is quantum field theory?\r"
expect -re "(.+)$prompt"
puts -nonewline [join [lrange [lmap line [split $expect_out(1,string) \n] {regsub {\r$} $line ""}] 1 end] "\n"]
``
Then stdout will contain only the output of the command and nothing else.
Bibliography:
* https://unix.stackexchange.com/questions/239161/get-the-output-from-expect-script-in-a-variable/792645#792645
* https://stackoverflow.com/questions/45210358/expect-output-only-stdout-of-the-command-and-nothing-else/79517903#79517903
* https://stackoverflow.com/questions/57975853/how-to-read-the-send-command-output-in-expect-script title is wrong, OP wants exit status apparently not stdout
Back to article page