capturing output from os.system() in Windows?

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Apr 23 04:40:30 EDT 2003


On Wed, Apr 23, 2003 at 01:03:33AM -0700, David wrote:
> Being a complete novice at python, I thought I'd try a simple script
> to run a NET VIEW (which runs in a DOS box) command under Windows and
> then manipulate the resulting data.
> 
> The first problem I have encountered is how to capture the output from
> the 'NET VIEW' command.
> 
> os.system('NET VIEW') returns 0 under windows, although the DOS box
> pops up and the NET VIEW executes correctly.

Try this:

    import commands
    status, output = commands.getstatusoutput('NET VIEW')

-Andrew.






More information about the Python-list mailing list