fork, pipe exec and dub2
问题 This code is supposed to print "Output from 'ls -l':" and append the result of 'ls -l', but it doesn't... Does anyone has a clue whats wrong with this? #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> void readStringFromFile (int file, char * readbuffer) { int nbytes = read(file, readbuffer, sizeof(readbuffer)); readbuffer[nbytes] = 0; } int main(int argc, char const *argv[]) { int fd[2]; pipe(fd); if (fork()==0)//child process { close(fd[0]); dup2(fd[1],1);