winnt win32process.createProcess with stdout to file ?

david.humpherys at gmail.com david.humpherys at gmail.com
Thu Mar 3 17:24:28 EST 2005


os:winnt
python2.3.2

I have a exe that dumps info to the command line.  I want to run this
process and  capture the stdout into a file.  I think i'm close... any
help appreciated.

dh
--------------------------------------------------------------------------
import win32process, win32file, win32security, win32con, win32api,
thread, win32event, win32pipe

cmd = "c:/myexe.exe"
sa = win32security.SECURITY_ATTRIBUTES()
sa.bInheritHandle = 1

startInfo = win32process.STARTUPINFO()
startInfo.dwFlags = win32process.STARTF_USESTDHANDLES

fh = win32file.CreateFile("c:/mylog.log", win32file.GENERIC_WRITE, 0,
sa, win32file.OPEN_EXISTING, win32file.FILE_FLAG_SEQUENTIAL_SCAN |
win32file.FILE_FLAG_OVERLAPPED , 0)
startInfo.hStdOutput = fh
startInfo.hStdError = win32api.GetStdHandle(win32api.STD_ERROR_HANDLE)
startInfo.hStdInput = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)

hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess
\
( None, cmd, None, None, 1, win32con.NORMAL_PRIORITY_CLASS, None, None,
startInfo)




More information about the Python-list mailing list