이것은 유닉스에서 사용하는 pipe fork exec trio의 간단한 데모입니다.파이프 포크와 execvp analogs 윈도우에서
#include <stdio.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <sys/types.h>
int main()
{
int outfd[2];
if(pipe(outfd)!=0)
{
exit(1);
}
pid_t pid = fork();
if(pid == 0)
{
//child
close(outfd[0]);
dup2(outfd[1], fileno(stdout));
char *argv[]={"ls",NULL};
execvp(argv[0], (char *const *)argv);
throw;
}
if(pid < 0)
{
exit(1);
}
else
{
//parrent
close(outfd[1]);
dup2(outfd[0], fileno(stdin));
FILE *fin = fdopen(outfd[0], "rt");
char *buffer[2500];
while(fgets(buffer, 2500, fin)!=0)
{
//do something with buffer
}
}
return 0;
}
이제 WinAPI를 사용하여 동일한 창에서 작성하고 싶습니다. 어떤 기능을 사용해야합니까? 어떤 아이디어?
약 : http://msdn.microsoft.com/en-us/library/3xw6zy53.aspx – Sebastian