0
운영 체제가 새로 도입되었으며 아래 언급 된 다음 명령을 실행하려고하지만 작동하지 않는 이유를 해결할 수 없습니다. ls -l | grep D 실행 중 오류 발생 D | grep De
나는 명령ls -l | grep D|grep De
을 실행하려고이 내 코드입니다 -
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
int fd[2];
int fd2[2];
pipe(fd);
if(!fork())
{
pipe(fd2);
if(!fork())
{
close(0);
dup(fd[0]);
close(1);
close(fd[1]);
dup2(fd2[1],fd[0]);
close(fd[0]);
execlp("grep","grep","D",NULL);
}
else
{
close(fd[0]);
dup(fd2[0]);
close(fd[1]);
execlp("grep","grep","De",NULL);
}
}
else
{
close(1);
dup(fd[1]);
close(0);
execlp("ls","ls","-l",NULL);
}
return 0;
}
이 명령을 실행하도록 도와주세요.
이#include <stdio.h>
#include <string.h>
int main()
{
char command[50];
strcpy(command, "ls -l | grep D|grep De");
system(command);
return(0);
}
system
명령은 호스트 환경에 명령에 의해 지정된 명령 이름 또는 프로그램 이름을 통과 실행되는 : 여기