开发者

How to implement linux pipeline in windows using C\C++

开发者 https://www.devze.com 2023-01-30 21:11 出处:网络
for example, in linux the following command $ firstProgram | secondProgram carries the output of firstProgram as an input to secondProgram

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

0

精彩评论

暂无评论...
验证码 换一张
取 消