How to get the user/group name from uid/gid in python ?

2008-01-19 Thread raocheng
We know that we can get process or file's uid/gid in python. For example: $ python >>> import os >>> os.getuid() 1516 >>> os.getgid() 102 >>> os.geteuid() 1516 >>> os.getegid() 102 >>> os.getgroups() [102, 600] >>> $ python >>> import os,stat >>> uid = os.stat("./file1")[stat.ST_UID] >>> gid = os

How to use only a sub shell to execute many commands in python

2008-01-18 Thread raocheng
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because it is too expensive. I want to use only one sub shell to execute all these commands and want to get each