childc.exe
程序是这样的:
#include<stdio.h>
#include<windows.h>
int main()
{
printf("this is apple pie\n");
return 0;
}
和主程序调用fork()
然后execl()
进行处理childc.exe
。代码如下:
#include <stdio.h>
#include<windows.h>
#include<unistd.h>
int main()
{
int fd[2];
if(pipe(fd)==-1)
{
printf("pipe failed\n");
exit(1);
}
pid_t pid=fork();
if(!pid)
{
dup2(fd[1],1);
close(fd[0]);
execl("childc.exe","childc.exe",NULL);
}
dup2(fd[0],0);
close(fd[1]);
char line[100];
scanf("%[^\n]",line);
printf("the line is:%sand this is the end\n",line);
return 0;
}
我希望有这个输出:
the line is: this is apple pie
and this is the end
但实际输出是:
and this is the end apple pie
请帮忙。