Are pexpect.spawn objects inactive until expect (or interact, send, etc) is called, or does the invoked process start immediately? For example:
import pexpect
process = pexpect.spawn("echo HELLO")
print ("Process created? Or run?")
process.expect("HELLO")
When the print statement occurs, has pexpect already run the echo command under the covers and is just holding off on letting it return until the expect call is processed? Or has nothing happened (echo hasn’t run) until the first call to expect or similar?
Cheers
When passed a command,
pexpect.spawn()forks and invokes the command immediately. The echo command in your example would have been run already.This is implied in the
spawnconstructor documentation:I’ve confirmed this by looking at the source code; the constructor calls
_spawn()which is documented as follows: