|
-
November 20th, 2006, 05:00 PM
#1
CreateProcess and redirect StdOut to a text file
I am using CreateProcess to execute a command line call
I want to redirect the StdOut and StdErr to a text file
All the examples I can find show how to send StdOut to a pipe, by using CreatePipe and assigning the handle to STARTUPINFO.hStdOut
I dont want to do this as the output is huge and can exceed max buffer size...
I tried to use CreateFile to give me a handle to a new file, and gave this to both hStdOut and hStdErr of my STARTUPINFO, but the file always comes up empty!
Any ideas how to redirect CreateProcess StdOut and StdErr to a new text file!
All code on this page is protected by an SEP field!!!
-
November 20th, 2006, 06:08 PM
#2
Re: CreateProcess and redirect StdOut to a text file
Why not just PIPE (>>) it? One pipe is the same as APPEND.
Code:
Option Explicit
Private Sub Form_Load()
Shell ("C:\Windows\System32\cmd.exe /c " & _
"C:\Windows\System32\ipconfig >> d:\myip.txt"), vbNormalFocus
End Sub
-
November 21st, 2006, 05:54 AM
#3
Re: CreateProcess and redirect StdOut to a text file
I dont want to use Shell, as I want to be able to test for System Errors!
i.e. CreateProcess throws LastError for things like "File not found" and other system errors etc...
CreateProcess does not allow redirects in the command line, it uses the STARTINFO to direct the StdOut and StdError to file handles
All code on this page is protected by an SEP field!!!
-
November 21st, 2006, 06:21 AM
#4
Re: CreateProcess and redirect StdOut to a text file
Sorry, can't give you a code right now, but you need to use the CreatePipe function to create, erm, pipes, then pass the STARTF_USESTDHANDLES flag to dwFlags in the STARTINFO structure, as well as setting the hStdOutput and hStdError to the pipes you created with CreatePipe. The pipes can then be read with ReadFile.
Sorry, I can't give you a code right now, but I hope that helped.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|