Consider the following 2 lines of code
sprintf(comm, "cat %s.bz2 | bunzip2 -dc", string);  
fp = popen(comm, "r");
If I am opening a file and the file doesn't exist, I will simply get a NULL file. However if I use popen to pipe a file through bunzip2, if the underlying file doesn't exist, or is corrupt, then fp will have a valid pointer and not NULL. The obvious way to check would seem to be to check the exit status of the command run by popen, but this doesn't seem possible.
Is there an easy way to make popen return null if a command fails?
 
    