How to implement linux pipeline in windows using C\C++
for example, in linux the following command
$ firstProgram | secondProgram
carries the output of firstProgram as an input to secondProgram
the b开发者_JS百科asic code in C that makes it happen in linux is
#include <unistd.h>
.
.
.
int fd[2];
forkStatus = fork();
if (status == 0)
{
close(1);
dup(fd[1]);
close(fd[1]);
close(fd[0]);
execv("firstProgram",...);
}
forkStatus = fork();
if (status == 0)
{
close(0);
dup(fd[0]);
close(fd[1]);
close(fd[0]);
execv("secondProgram",...);
}
close(fd[1]);
close(fd[0]);
i need to do something similar in windows. thanks
See the Win32 CreatePipe()
to create an anonymous pipe. This example (titled "Creating a Child Process with Redirected Input and Output") shows how to replicate your code in Win32.
In the linux version you are basically redirecting the input and output. This can be done using the native Win32 API or if .NET is permissible System.* library. you can find more examples on MSDN http://msdn.microsoft.com/en-us/library/ccf1tfx0.aspx
精彩评论