I'm attempting to write a program in which the program executes a shell command. This shell command then outputs some value to stdout, and I would like to be able to read that output from within my program. I am attempting to achieve this via pipes, and have written the following code:
As best as I can figure, this should result in that command line output being stored in "to".Code:int desc; char to; pipe(desc); dup2(fileno(stdout),desc); execv("ifconfig en0 | grep ether",NULL); read(desc,to,sizeof(to)); close(desc); close(desc);
The code compiles, runs, and I end up with the variable "to" containing a single '\0' character, rather than grep's output to stdout. Pipe's are a new area for me, and so I'm pretty sure the problem lies in my creation of the file descriptors.
Any help is greatly appreciated.