os.system question

Larry Wang lwanga at gmail.com
Thu Aug 7 03:40:20 CEST 2008


os.system() simply executes the command in a subshell, and returns the 
command's exit status which in your case is '0'. If you need to capture the 
stdout, stderr, etc. stuff, subprocess module is preferred which offers more 
powerful functionalities over os.system().

Nessus

"Kevin Walzer" <kw at codebykevin.com> wrote in message 
news:1c5bf$489a4add$4275d90a$15022 at FUSE.NET...
> >>> import os
> >>> foo = os.system('whoami')
> kevin
> >>> print foo
> 0
> >>>
>
> The standard output of the system command 'whoami' is my login name. Yet 
> the value of the 'foo' object is '0,' not 'kevin.' How can I get the value 
> of 'kevin' associated with foo?
>
> -- 
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com 




More information about the Python-list mailing list