<http://www.micrognu.com/proj/nocost/wpipe/>
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, with one Front-Cover Text: "WinPipe software
and documentation are available free of charge at
<http://www.micrognu.com/proj/nocost/wpipe/>", and with no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU Free Documentation License".
WinPipe is a combination of a utility and a dynamic link library which allows an application to spawn a child process with a wide range of abilities for manipulating the standard console handles of the child. The purpose of WinPipe was to overcome problems and limitations related to standard I/O redirection of Windows console applications.
The normal way of redirecting console input and output under MS Windows is explained by Microsoft in the article "Creating a Child Process with Redirected Input and Output." The method used by Microsoft is a call to the CreateProcess API function with the standard handles redirected to pipes.
There are several problems with this method. One problem is that many Windows Console API functions will not work properly when the console is redirected in this way. The standard windows console handles point to Console Screen Buffer and Console Input Buffer objects, a pipe will only function equivalently to these objects when passed to ReadFile, WriteFile, or PeekNamedPipe. Redirecting with a pipe will often work because library I/O functions, such as those defined in stdio.h usually operate by calling one of these three functions.
If you are writing a program intended to interface with applications you did not write, you may not be guaranteed that the child process will only call functions that work with pipes. For example, if the child process with standard input redirected to a pipe were to call the ReadConsoleInput Windows API function with a handle to the standard input as returned from the GetStdHandle API function, an error will result.
Another problem with the Microsoft method is that when standard output or standard error is redirected to a pipe, the write end of the pipe must be closed before the read end can be read. This will work if the child process delivers all of its output and terminates, but will not work if the child process sends output and then waits for more input before delivering more output.
A solution to the second problem is presented by Mykle Hoban in the article "Using anonymous pipes to redirect standard input/output of a child process." While Hoban’s solution salves one of the problems with the Microsoft method, it also creates a few new ones. For one thing it does not properly process command keystrokes, such as the backspace key. Another problem is that it does not properly process buffered output. It will not work properly if it is used with a child process that uses stdio.h to generate its output. This effect can be seen by using Hoban’s example code and change the value of the app_spawn to “[path to system directory]\\ftp.exe” this is the dos ftp program that is included as part of the standard Windows distribution.
WinPipe was created as a solution to these problems. WinPipe allows an application to spawn a child process with a console environment separate to the parent process console (if the parent has one). WinPipe also allows the parent to manipulate the standard input, standard output and standard error handles of the child process. In this way the parent process can send input to the child or read output from the child. Because all of this is done threw Console Screen Buffers and Console Input Buffers, the child process can successfully call any Windows Console API function.
Examples
WPipeCreate
WPipeClose
WPipeWaitForExit
WPipeReadConsoleOutput
WPipeReadConsoleOutputAttribute
WPipeReadConsoleOutputCharacter
WPipeReadLn
WPipeFillConsoleOutputAttribute
WPipeFillConsoleOutputCharacter
WPipeFlushConsoleScreenBuffer
WPipeScrollConsoleScreenBuffer
WPipeFlushConsoleInputBuffer
WPipeGenerateConsoleCtrlEvent
WPipeSendKeyEvent
WPipeWriteConsoleInput
WPipeWriteLn
WPipeGetConsoleCursorInfo
WPipeGetConsoleMode
WPipeGetConsoleScreenBufferInfo
WPipeGetConsoleTitle
WPipeGetNumberOfConsoleInputEvents
WPipeSetConsoleCursorPosition
WPipeSetConsoleScreenBufferSize
WPipeSetConsoleTextAttribute
