例如,在 linux 中,下面的命令
$ firstProgram | secondProgram
将 firstProgram 的输出作为 secondProgram 的输入
使它在 linux 中发生的 C 中的基本代码是
#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]);
我需要在 Windows 中做类似的事情。谢谢