qemumonitor 897 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env expect
  2. # Ee have to use expect since QEMU 2.12: just piping commands
  3. # into telnet stopped working at that version.
  4. spawn telnet localhost 45454
  5. set prompt "\n(qemu) "
  6. expect $prompt
  7. if {$argc > 0} {
  8. send "[concat [join $argv " "]]\r"
  9. expect $prompt
  10. } else {
  11. interact
  12. }
  13. # In order to treat input from stdin, we would need to differentiate between input from pipe vs terminal.
  14. # For bash we can do it as:
  15. # https://stackoverflow.com/questions/911168/how-to-detect-if-my-shell-script-is-running-through-a-pipe
  16. # but no one knows for Tcl:
  17. # https://stackoverflow.com/questions/43660612/how-to-check-if-stdin-stdout-are-connected-to-a-terminal-in-tcl
  18. # One option would also be to have a bash wrapper that calls this tcl script.
  19. # Related: https://stackoverflow.com/questions/10237872/expect-redirect-stdin
  20. #while {[gets stdin line] > 0} {
  21. #expect $prompt
  22. #send "$line\r"
  23. #}