winnt win32process.createProcess with stdout to file ?

Roger Upole rupole at hotmail.com
Thu Mar 3 19:10:50 EST 2005


You'll need to pass security attributes with inherit=True
to CreateProcess also, and the file has to be opened with sharing.
(win32file.FILE_SHARE_READ|win32file.FILE_SHARE_WRITE)
Also, you shouldn't have FILE_FLAG_OVERLAPPED set if you're
not passing an overlapped object into CreateFile.

   hth
      Roger


<david.humpherys at gmail.com> wrote in message 
news:1109888668.434725.94760 at f14g2000cwb.googlegroups.com...
> 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)
> 



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----



More information about the Python-list mailing list