Running one Python program from another as a different user
Alessandro Bottoni
alessandro.bottoni at infinito.it
Sat Aug 13 08:44:40 EDT 2005
Jeff Schwab wrote:
> dwelch91 at gmail.com wrote:
>> Thanks, that looks very promising...
>> Is there a solution for pre-Python v2.4? I have to have code that works
>> on 2.x, 0<=x<=4. Do I just use the os.popen instead?
>
> import os
>
> def run_as(username):
> pipe = os.popen("su %s" % username, 'w')
> pipe.write("whoami")
>
>
> if __name__ == "__main__":
> import sys
> for user in sys.argv[1:]:
> run_as(user)
Jeff, may I suggest you to write down a new recipe for the ASPN Python
Cookbook based on these code snippets? This is exactly the kind of thing
the people is happy to find at ASPN.
CU
-----------------------------------
Alessandro Bottoni
More information about the Python-list
mailing list