Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] executing a command that requires root from a python script



Hi,

I would like to execute a command that requires root privileges from a
python script, for example something like "su -l -c ifconfig"
 (I don't want my entire python script running with root privileges).
I can execute the command using subprocess.Popen(), but I am required to enter
the root password with the keyboard. I would like the python script
to enter the password

I have tried to do something like
keyb = StringIO.StringIO()
keyb.write('rootpass\n')
subproc = subprocess.Popen(["su","-l","-c","ifconfig"], stdin=keyb)

to try to create a file-like object and feed it as stdin to the subprocess,
but it doesn't work (got an error)

Is it possible to do this?


Thanks,

Hector


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links