1

I am trying to read and write to guest-vm console using the POPEN command. Reading(stdout) works fine, but when i add the stdin to POPEN i get the "Cannot run interactive console without a controlling TTY". Appreciate any suggestion on how to overcome this error.

p = Popen(["virsh", "console", "guest-vm"],
          shell=False, stdin=PIPE, stdout=PIPE, close_fds=True)

for line in iter(p.stdout.readline, b''):
    if line == "SUCCESS":
        p.stdin.write('\n')

ERROR: error: Cannot run interactive console without a controlling TTY

user245011
  • 65
  • 1
  • 9
  • you could use `pexpect`, `pty` modules to provide a pseudo-tty. Here's a [code example, how to read output using pty](http://stackoverflow.com/a/12471855/4279) (your case is similar but you need a `select` loop to interleave reading/writing, see [how `pty.spawn()` is implemented](https://github.com/python/cpython/blob/3f409f756b7b8f75c4543b2c31566bd8b8dbb3dd/Lib/pty.py#L119-L170)). – jfs Jul 23 '15 at 23:40

1 Answers1

4

Did you tried:

ssh -t <user>@<libvirthost> virsh console <vm_name>

where: user - user that exist on libvirthost libvirthost - where libvirt VM is running

More here

Lukino
  • 1,407
  • 13
  • 14
  • Well, I don't care much. I still have similar problem, I run into this question and many others, so I though that might help him. Anyway, at least explanation would be helpful (from downvoter) – Lukino Jul 22 '15 at 16:03