[Tutor] how to get response from os.system()

Nathan McBride nomb85 at comcast.net
Mon Mar 17 00:10:18 CET 2008


Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to work with mysqldump piping to gzip 

-----Original Message-----
From: Jeff Younker <jeff at drinktomi.com>
Sent: Sunday, March 16, 2008 6:59 PM
To: Nathan McBride <nomb85 at comcast.net>
Cc: tutor at python.org
Subject: Re: [Tutor] how to get response from os.system()


> Would you mind perhaps show an example running an interactive  
> command like su and show how to send input to the commands waiting  
> propmts?

If you're doing that then you *really* want to be using the pexpect
module.

cmd = pexpect.spawn('su - SOMEINTERACTIVECOMMAND')
cmd.expect('# ')   # the prompt
cmd.sendline('A COMMAND')
cmd.expect('# ')   # wait for the prompt again
output = cmd.before  # the stuff before the prompt
cmd.sendline('exit')
cmd.close()


- Jeff Younker - jeff at drinktomi.com -





More information about the Tutor mailing list