Anonymous Pipe Operations

The CreatePipe function creates an anonymous pipe and returns two handles: a read handle to the pipe and a write handle to the pipe. The read handle has read-only access to the pipe, and the write handle has write-only access to the pipe. To communicate using the pipe, the pipe server must pass a pipe handle to another process. Usually, this is done through inheritance; that is, the process allows the handle to be inherited by a child process. The process can also duplicate a pipe handle using the DuplicateHandle function and send it to an unrelated process using some form of interprocess communication, such as DDE or shared memory.

A pipe server can send either the read handle or the write handle to the pipe client, depending on whether the client should use the anonymous pipe to send information or receive information. To read from the pipe, use the pipe's read handle in a call to the ReadFile function. The ReadFile call returns when another process has written to the pipe. The ReadFile call can also return if all write handles to the pipe have been closed or if an error occurs before the read operation has been completed.

To write to the pipe, use the pipe's write handle in a call to the WriteFile function. The WriteFile call does not return until it has written the specified number of bytes to the pipe or an error occurs. If the pipe buffer is full and there are more bytes to be written, WriteFile does not return until another process reads from the pipe, making more buffer space available. The pipe server specifies the buffer size for the pipe when it calls CreatePipe.

Asynchronous (overlapped) read and write operations are not supported by anonymous pipes. This means that you cannot use the ReadFileEx and WriteFileEx functions with anonymous pipes. In addition, the lpOverlapped parameter of ReadFile and WriteFile is ignored when these functions are used with anonymous pipes.

An anonymous pipe exists until all pipe handles, both read and write, have been closed. A process can close its pipe handles by using the CloseHandle function. All pipe handles are also closed when the process terminates.

Anonymous pipes are implemented using a named pipe with a unique name. Therefore, you can often pass a handle to an anonymous pipe to a function that requires a handle to a named pipe.

Send comments about this topic to Microsoft

Build date: 11/12/2009

Tags :


Community Content

LabBoy
How can I capture the DOS output while it is still running?
Hello Everybody,

I have a Third Party Tools (*.exe), for do something. Its processing takes a lot of time (3-5 minutes)
While it is running, it print out many information to the DOS screen continuously.

I wanted to capture the DOS output (DOS screen), and show its output on the GUI application at the same time (without waiting).
I mean that, I want to see the execution progress of the *.exe (DOS output) on the GUI.

I used the API functions (CreatePipe(), CreateProcess(), PeekNamedPipe() and ReadFile()) it look like some MSDN examples.

I found out the problem, it is

while the *.exe is still running, the PeekNamedPipe () could tell that no a message in the Pipe. And, if use the ReadFile(), the programe will still wait here here until the *.exe finished or terminated.

Could sombody please tell me that "How to capture the DOS output while it is running?"

Thanks in advance,
LB.
Tags :

Page view tracker