os.system and command output

Steve Holden steve at holdenweb.com
Wed Jun 7 21:26:05 CEST 2006


A.M wrote:
> Hi,
> 
> 
> 
> How can I run an OS command and have the command's output (to stdout) in my 
> string variable?
> 
> 
> 
> For example in windows, this command should return a list of files within 
> directory:
> 
> 
> 
> os.system("DIR")
> 
> 
> 
> I am looking for an alternative function that returns the DIR command output 
> in a string
> 
Try:

s = os.popen("DIR").read()

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list