[Tutor] python newbie..system call help

Martin Walsh mwalsh at groktech.org
Fri Jul 15 03:51:28 CEST 2005

Mike Pindzola wrote:
> I have figured many things out. system works, i just forgot to type 
> os.system(). I have been looking into the os module and am finding alot 
> of useful stuff. I still need to workout the best way to ask a user for 
> a root password, show **** when typed and then pass it to the system...

Since you're using linux -- you might also try the pexpect module found 


I've found it very useful for interacting with the shell. I don't 
believe a windows version is available, however.

Here's a very basic and untested example:

import pexpect # you'll have to install pexpect first, of course
import getpass

pexpect.spawn('sudo -k') # timeout any existing sudo session
child = pexpect.spawn('sudo mount /mnt/foo')
mount_results = child.read()
print mount_results

More information about the Tutor mailing list