I am trying to create a function that takes a shell command as an argument, uses fork to create a new process that executes the command. I also want to redirect the standard output of the command so that the calling function can read it using the FILE * pointer.
static FILE* runCommand(char* command){ int pfd[2]; if(pipe(pfd)<0) return NULL; if(pid=fork()==0){
}
I'm not sure how to return a file pointer that can be used to read the output of a command. Also, is this the correct way to execute a command on a shell?
ps. I read about popen, but there is a good reason why I cannot use it, so I have to implement this functionality myself.
thanks
source share