Hi all,
I'm trying to redirect the output of a dos or console program to a file. According to the win32 progammer's reference, this can be done by setting the stdhandles of a STARTUPINFO structure to file handles. I'm currently using this:
;==========start of code ========
; get startup info
invoke GetStartupInfo, ADDR ProgSI
invoke CreateFile, ADDR TempOutputFile, GENERIC_WRITE, FILE_SHARE_WRITE or FILE_SHARE_READ,\
NULL, CREATE_ALWAYS, NULL, NULL
mov hOutputFile, eax
invoke CreateFile, ADDR TempErrorFile, GENERIC_WRITE, FILE_SHARE_WRITE or FILE_SHARE_READ,\
NULL, CREATE_ALWAYS, NULL, NULL
mov hErrorFile, eax
invoke CreateFile, ADDR TempInputFile, GENERIC_READ, FILE_SHARE_WRITE or FILE_SHARE_READ,\
NULL,CREATE_ALWAYS, NULL, NULL
mov hInputFile, eax
mov ProgSI.hStdInput, eax
push hOutputFile
pop ProgSI.hStdOutput
push hErrorFile
pop ProgSI.hStdError
or ProgSI.dwFlags,STARTF_USESTDHANDLES
invoke CreateProcess, ADDR CommandBuffer, NULL, NULL, NULL, NULL,\
TRUE, NULL, NULL, ADDR ProgSI, ADDR ProgPI
;==========end of code ========
CreateProcess returns 1 to indicate success, but when I call:
invoke WaitForSingleObject, ProgPI.hProcess, INFINITE
to wait for the program to quit, it waits forever and nothing is written to the output files.
What's wrong?
Thomas
Read my pipe tutorial
This works but it hangs on ReadFile if it's running a .bat file (it outputs everything but hangs at the end).
Thomas