[Tutor] how to get response from os.system()
Jeff Younker
jeff at drinktomi.com
Sun Mar 16 23:59:28 CET 2008
> 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