os.system question

Brad bmalone at berkeley.edu
Mon Aug 11 21:55:06 EDT 2008


Kevin Walzer wrote:
>  >>> 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?
> 

Hi Kevin, check out popen. It should let you do what you want.

import os
name=os.popen('whoami').read()



More information about the Python-list mailing list