1) In above code, system("some command") is passed on to the command processor. rv is the return value, that says if "some command" actually passed or failed. I want to access the actual return value from "some command" and take decisions based on that. How would I do that?
2) If it cannot be done using "system" command, any other way to do that?
@helios and (anyone else who knows): The value of rv indicates if "some command" within system(), passed or failed and that's about it. I am looking for a way to detect return value of that "some command".
Let's say "some command" has 5 different return values, and calling function needs to take decision based on that (and not based on whether that command was either executed or not), how would I do that?
The man page spells it out (n4nature just didn't include all of the text):
The value returned is -1 on error (e.g. fork() failed), and the return status of
the command otherwise. This latter return status is in the format specified in
wait(2). Thus, the exit code of the command will be WEXITSTATUS(status). In case
/bin/sh could not be executed, the exit status will be that of a command that does
exit(127).