Let's assume I am running a unix command using system("foocmd param1")
on c++.
If foocmd
returns "Invalid argument" back to the terminal via stderr, then how do I get my c++ code to know whether foocmd
failed?
Here is my attempted solution:
My assumption is that I should check whether anything got returned to stderr by calling the command. To do that, I tried switching over to popen. Currently, this is the way I check. I first output my stderr into a file.
sprintf(cmd, "foocmd param1 2>temp.txt");
system(cmd);
Then I check if temp.txt is empty or not.
But there has to be a better way. Can anyone lend me a hand?