Redirecting the output from sys.stdout
Fred Gansevles
gansevle at cs.utwente.nl
Thu Apr 13 10:23:19 EDT 2000
Pieter Claerhout wrote:
> Hello,
>
> I want to run a DOS command from Python, and I want to redirect the output of
> that command to a variable. Anyone a suggestion on how to accomplish this? The
> output of the command should not be shown on the screen.
>
> Kind regards,
>
> Pieter
>
> [ Pieter Claerhout :: CreoScitex Response Centre :: Applications support ]
> [ Pieter_Claerhout at creoscitex.com :: http://www.creoscitex.com/ ]
> [ CreoScitex Europe :: Excelsiorlaan 21 :: 1930 Zaventem :: Belgium ]
My favorite:
def run (*args, **kw):
import win32pipe
command = string.join (args)
i, o, e = win32pipe.popen3 (command)
if kw.has_key ('send'):
i.write (kw['send'])
i.close ()
out = o.read ()
err = e.read ()
return out # discard stderr output
...
bat_files = run ("dir /s *.bat")
___________________________________________________________________________
Fred Gansevles <mailto:Fred.Gansevles at cs.utwente.nl> Phone: +31 53 489 4613
>>> Your one-stop-shop for Linux/WinNT/NetWare <<<
Org.: Twente University, Fac. of CS, Box 217, 7500 AE Enschede, Netherlands
"Bill needs more time to learn Linux" - Steve B.
More information about the Python-list
mailing list