Control a process interactively (pexpect) and save data
piotrek at nonexistent.domain
Wed May 6 16:20:01 CEST 2009
I'm trying to use something like pexpect.interact() but I want to save
all my inputs and save all outputs from the process (/bin/sh Linux).
The main goal is to record all sequence of commands and responses in
order to automatically generate pexpect script.
My script is like below so far, but I'm unable to print responses to
stdout and save it to variables/files/whatever.
p = pexpect.spawn('/bin/sh')
print "PID: " + str(p.pid)
p.logfile = sys.stdout
if not p.isalive():
print "Not alive"
bb = sys.stdin.readline()
pexpect.interact() doesn't allow to save input and output.
I tried pipes but I've found that "Don't use a pipe to control another
application..." - http://edgysoftware.com/doc/python-pexpect/doc/
I tried subprocess module but it didn't allow me to control /bin/sh as
communicate() method do as follows
"Interact with process: Send data to stdin. Read data from stdout and
stderr, until end-of-file is reached. Wait for process to terminate. The
optional input argument should be a string to be sent to the child
process, or None, if no data should be sent to the child."
So it "waits for process to terminate" and I'm unable to interact...
Oh, and by the way my script works with /bin/sh but doesn't work with
/bin/bash. If I enter 'exit' sh exits, bash does not... Why?
More information about the Python-list