[Tutor] issuing system commands

Kent Johnson kent37 at tds.net
Fri Jan 26 13:30:27 CET 2007


Dan Klose wrote:
> Hi All,
> 
> I am trying to break my nasty habit of doing EVERYTHING in perl and for 
> this task I figure python is one of the better options.
> 
> I would like to do several things:
> 
> 1. take user input - this will be a password
> 2. use some sort of function that converts the unser input to * or the 
> typical '' no output of linux.

See getpass.getpass()

> 3. Take this input and use it in the os.system to issue an su command.
> 
> All I have so far is:
> 
> import os, sys
> password = raw_input('Enter USER password: ')
> print "you entered ", password
> os.system("su perlmunky password")
> 
> I guess point three is more of a system dependent problem - As I work on 
> a mac and linux is there a better way of issuing these commands?  All I 
> really want to do is mount/unmount directories and shift / delete 
> files.  I know how to do this in perl, but as I said I really want to 
> kick the habit.

Not sure what you mean by mounting a directory but you can manipulate 
files and directories directly in Python. See the os and shutil modules.

Kent



More information about the Tutor mailing list