How can you know if popen()
succeeded/done running the shell or failed?
popen return value:
Upon successful completion, popen() shall return a pointer to an open stream that can be used to read or write to the pipe. Otherwise, it shall return a null pointer and may set errno to indicate the error.
fp = popen("ls *", "r");
if (fp == NULL)
/* Handle error */;
Assuming you mean running popen in C code, you can check the man page. It says that popen will return NULL if it fails, and it returns a file stream otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With