Capturing a ret val of C obj file in ksh script

Hi,

I have one shell script which is calling a C executable. That C executable returns a value depending upon operations inside the C code. But how to get that value in the calling shell script?

The syntax of calling the C executable is like --
C_exec <argc no> <argument1> <argument2> etc ...

When I am doing
return_value=C_exec <argc no> <argument1> <argument2> etc ...

The runtime error is shown as --
<argc no>: not found

Pls help.

Bijitesh

Something like...

/path/to/C_exec <argc no> <argument1> <argument2>
return_value=$?

if your value is between 0-255 simply use
exit( ret ); in your c-code. echo $? is the exitcode of the last cmd and your value.

The return status (what you want) is stored in the $? variable

/path/to/C_exec <argc no> <argument1> <argument2>
retval=$?
if [ $retval -eq 0 ] ; then
  echo "success"
else
  echo "failure"
fi

This test is for a simple 0 = success, anything else = failure

Thanks vino for ur reply. But that syntax is not working.
Instead grumpf's suggestion is working. Thanks grumpf and jim mcnamara.

My problem is solved. But, just out of curiosity, I want to know the way of returning a character string or simply a character from C executable to calling shell script.

Thanks in advance,
Bijitesh

The exit code mechanism is working basicly since main() is int. What you see on shell is the return
code of main() (using void main() is therefore a BAD idea).
A string is something different. The easy way retvar=$( myprg ) works only IFF there is no
other output.