Robert Jackson wrote: > I'm trying to write a function that checks to see if the user that > is running the python script is 'root' (I'm obviously running this > Python program on Linux). > > > > Using os.system(), I have done something like this: > > >>>> import os > >>>> os.system("whoami") > > robert > > 0 > > > > > If I try to assign the output of this snippet of code to a variable, > the variable ultimately ends up holding "0" and not the username. > > > > I have seen some examples on Google where some individuals have suggested > something like this: > > user=os.system("whoami") > if user is not "root": > print "You aren't root. Goodbye." > sys.exit() > > But that isn't going to work, for obvious reasons (user holds 0, and not the > username). How do I get around this problem? > > Robert > > > > > > > ____________________________________________________________________________________ > Moody friends. Drama queens. Your life? Nope! - their life, your story. Play > Sims Stories at Yahoo! Games. > http://sims.yahoo.com/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > maybe this
import os, sys # we need to be root if os.getuid(): print "You need to be root, so we now die." sys.exit(0) -- Norman Khine %>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] ) _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor