os.system just returns an exit code (or 0 on windows platforms). If
you want your program to read the output produced by a command try
os.popen (or popen2 or popen3 or popen4 -- RTFM).
f = os.popen('...command string ..., 'r')
result = f.read()
The output of your small example is, perhaps, confusing. The user
name is printed by the python print statement, but the group name
'staff' is not printed by python. Here's what happened. The executed
echo command sends its output to the controlling terminal (that's why
you see the word 'staff'), but it does not communicate back to python
through the os.system call. The return value of the os.system call
(evidently zero) is assigned to the group variable but is not
printed. (The assignment statement in python never prints to the
screen.) Finally your print statement show the value of the group
variable to be zero.
···
On Tuesday 06 November 2001 07:55 am, Adinda Praditya wrote:
Take a look at this:
>>> import os
>>> user = os.getenv('USER')
>>> print user
dida
>>> group = os.system('set -- `groups $USER`; echo $3')
staff
>>> print group
0
How did this happened? The reason i create this is for managing users. I
run python in my environment. How can i take the (os.system...) value?