How To Create a Process for Reading and Writing to a Pipe (173085)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Control Creation Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
This article was previously published under Q173085 SUMMARY
This example illustrates a Visual Basic application starting another
process with the purpose of redirecting that process's standard IO handles.
The Visual Basic application redirects the created process's standard
output handle to an anonymous pipe, then proceeds to read the output
through the pipe. This sample just redirects STDOUT of the new process. To
redirect other handles (STDIN and STDERR), create a pipe for each handle
for which redirection is desired. The Visual Basic application would read
from the read ends of the pipes for the redirected STDOUT and STDERR. If
STDIN redirection was desired, the Visual Basic application would write to
the write end of the appropriate pipe. An example follows:
'A pipe for redirection of STDOUT
CreatePipe(hReadPipe1, hWritePipe1, sa, 0)
'A pipe for redirection of STDERR
CreatePipe(hReadPipe2, hWritePipe2, sa, 0)
'A pipe for redirection of STDIN
CreatePipe(hReadPipe3, hWritePipe3, sa, 0)
'Preparing to start the process with redirected handles
start.hStdOutput = hWritePipe1
start.hStdError = hWritePipe2
start.hStdInput = hReadPipe3
'Reading output from the started process's STDOUT
ReadFile(hReadPipe1, mybuff1, 100, bytesread, ByVal 0&)
'Reading output from the started process's STDERR
ReadFile(hReadPipe2, mybuff2, 100, bytesread, ByVal 0&)
'Writing to the started process's STDIN
WriteFile(hWritePipe3, mybuff3, 100, byteswritten, ByVal 0&)
Modification Type: | Minor | Last Reviewed: | 6/29/2004 |
---|
Keywords: | kbhowto KB173085 |
---|
|