popen_spawn - use pexpect with a piped subprocess

Provides an interface like pexpect.spawn interface using subprocess.Popen

PopenSpawn class

class pexpect.popen_spawn.PopenSpawn(cmd, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None, encoding=None, codec_errors='strict')[source]
__init__(cmd, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None, encoding=None, codec_errors='strict')[source]
send(s)[source]

Send data to the subprocess’ stdin.

Returns the number of bytes written.

sendline(s='')[source]

Wraps send(), sending string s to child process, with os.linesep automatically appended. Returns number of bytes written.

write(s)[source]

This is similar to send() except that there is no return value.

writelines(sequence)[source]

This calls write() for each element in the sequence.

The sequence can be any iterable object producing strings, typically a list of strings. This does not add line separators. There is no return value.

kill(sig)[source]

Sends a Unix signal to the subprocess.

Use constants from the signal module to specify which signal.

sendeof()[source]

Closes the stdin pipe from the writing end.

wait()[source]

Wait for the subprocess to finish.

Returns the exit code.

expect()
expect_exact()
expect_list()

As pexpect.spawn.