Exit Code in HP-UX KSH.

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.

Can anyone help?

Like the man page says, you need to use the macros which are shown on the man page for wait() to decode the return value of system() if it is not -1.

Add, no, -1 is not 256 :stuck_out_tongue:

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:

if (success)
{
error = 0
}else{
error = 1
}

...

return(error)

where error is declared as an int.

What am I doing wrong?

}

I tell you what is wrong - me!

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) ...

Doh!