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
助けてください。