running an app as user "foo"

Simon Forman rogue_pedro at yahoo.com
Mon Jul 31 14:59:25 EDT 2006


bruce wrote:
> hi.
>
> within python, what's the best way to automatically spawn an app as a given
> user/group.
>
> i'm testing an app, and i'm going to need to assign the app to a given
> user/group, as well as assign it certain access rights/modes (rwx) i then
> want to copy the test app to a given dir, and then spawn a process to run
> the app..
>
> thanks

Look in the os module docs at the set*id() functions
http://docs.python.org/lib/os-procinfo.html

Then when you spawn the app using subprocess.Popen() you can pass a
function as the preexec_fn argument that changes the user and group ids
of the child "just before the child is executed"
http://docs.python.org/lib/node235.html




More information about the Python-list mailing list