Open a process with stdin connected to a pseudo-tty. :param cmd: command to run :type cmd: str :returns: (Popen, master) tuple, where master is the master side of the of the tty-pair. It is the responsibility of the caller to close the master fd, and to perform any c
(cmd, shell=True)
| 479 | |
| 480 | |
| 481 | def popen_tty(cmd, shell=True): |
| 482 | """ |
| 483 | Open a process with stdin connected to a pseudo-tty. |
| 484 | |
| 485 | :param cmd: command to run |
| 486 | :type cmd: str |
| 487 | :returns: (Popen, master) tuple, where master is the master side |
| 488 | of the of the tty-pair. It is the responsibility of the caller |
| 489 | to close the master fd, and to perform any cleanup (including |
| 490 | waiting for completion) of the Popen object. |
| 491 | :rtype: (Popen, int) |
| 492 | """ |
| 493 | master, slave = pty.openpty() |
| 494 | # pylint: disable=subprocess-popen-preexec-fn |
| 495 | proc = subprocess.Popen(cmd, |
| 496 | stdin=slave, |
| 497 | stdout=subprocess.PIPE, |
| 498 | stderr=subprocess.PIPE, |
| 499 | preexec_fn=os.setsid, |
| 500 | close_fds=True, |
| 501 | shell=shell) |
| 502 | os.close(slave) |
| 503 | |
| 504 | return (proc, master) |
| 505 | |
| 506 | |
| 507 | def wait_for_task(master, name, state, delay=1): |