OurBigBook About$ Donate
 Sign in+ Sign up
by Ciro Santilli (@cirosantilli, 37)

Get output of send command on expect

 ... Computer user-interface Command-line interface Command line utility List of command line utilities Expect Expect HOWTO
 0 By others on same topic  0 Discussions  Updated 2025-05-26  +Created 2025-03-20  See my version
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:
  • unix.stackexchange.com/questions/239161/get-the-output-from-expect-script-in-a-variable/792645#792645
  • stackoverflow.com/questions/45210358/expect-output-only-stdout-of-the-command-and-nothing-else/79517903#79517903
  • stackoverflow.com/questions/57975853/how-to-read-the-send-command-output-in-expect-script title is wrong, OP wants exit status apparently not stdout

 Ancestors (12)

  1. Expect HOWTO
  2. Expect
  3. List of command line utilities
  4. Command line utility
  5. Command-line interface
  6. Computer user-interface
  7. Software
  8. Computer
  9. Information technology
  10. Area of technology
  11. Technology
  12.  Home

 View article source

 Discussion (0)

+ New discussion

There are no discussions about this article yet.

 Articles by others on the same topic (0)

There are currently no matching articles.
  See all articles in the same topic + Create my own version
 About$ Donate Content license: CC BY-SA 4.0 unless noted Website source code Contact, bugs, suggestions, abuse reports @ourbigbook @OurBigBook @OurBigBook