Updated to work with pclose() failures