In one of my programs another process is called using the system command e.g.
lv_error = system("myproc");
where lv_error is declared as an int.
myproc would be returning 0 for success and 1 for failure. e.g.
if (success)
{
return(0);
}else{
return(1);
}
When the return code of myproc is examined in the shell via $? the value is reported correctly. When displayed in the calling C process a value of 0 or 1 is 256.
The man documentation is not very clear. It seems that 256 may correspond to -1 return code and that I should do some more checking after that.
Thanks. You are right about the -1 I was looking at something else!
The macro WEXITSTATUS didn't really make too much difference.
The called process will always return a value of 256 (Prior to running my test I check what the called process will return by running it on its own). I must assume that since a -1 is not explictly being returned, the called process is being run successfully.
Ok. With this in mind, I then replaced my called process with a dummy shell script which simply contained exit 0 or exit 1 depending on what condition I was testing.
When the dummy script is used then I will get 0 returned for 0 and 256 returned for 1. At least I can make sense of these return codes!
So the problem must be with the way the called process is returning its error code. To expand:
Please disregard this thread - there was no problem, the conditions that the called program was being run in, would always cause it to return 256 (or 0) ...