[Tutor] really stange behaviour

lonetwin lonetwin@yahoo.com
Mon, 5 Nov 2001 21:26:21 +0530


On Tuesday 06 November 2001 20:56, Adinda wrote:
> ....<snip>.........
> ...How can i take the (os.system...) value?

from the standard lib. docs.:

system(command)
  .....The return value is the exit status of the process encoded in the
  format specified for wait()....

This means that os.system() returns a value that reflects the success or 
faliure of the command that it executes, not the output of the command. It's 
a common mistake to assume otherwise. To get the output of a particular 
command you could use the commands module.

like so:
====================================================
>>> import commands
>>> op = commands.getoutput('echo foo')
>>> op
'foo'
>>> op = commands.getstatusoutput('echo foo')
>>> op
(0, 'foo')
>>>
=====================================================
hope that helps,

Peace
Steve

P.S: I know all you gurus would suggest something like a popen, I just wanted 
to make a mention of the "commands" module, which is a nice lil' thing 
specifically meant for these kinda problems ....*I Think* :)
----------------------------------------------
Every oak tree started out as a 
couple of nuts who stood their ground.
                                    Anonymous
----------------------------------------------