9

execlp() output cannot be redirected to stdout with pipe

view full story
linux-howto

http://stackoverflow.com – I have the following program: #include<iostream> #include<fcntl.h> #include<sys/types.h> #include<sys/wait.h> #include<unistd.h> using namespace std; int main() { int p[2]; int code; pid_t pid; if(-1==(pipe(p))) { cout<<"Pipe error!"<<endl; return 1; } if(-1==(pid=fork())) { cout<<"Fork error!"<<endl; return 1; } if(pid==0) { dup2(p[1],1);//duplicates stdout? close(p[0]);//closes reading end execlp("grep","grep","/bin/bash","/etc/passwd",NULL); return 1; } else { cout&lt (HowTos)