![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| capturing line from script output and appending to a file | wally_welder | Shell Programming and Scripting | 6 | 08-31-2007 12:03 AM |
| Capturing last command execution status in a script. | videsh77 | Shell Programming and Scripting | 2 | 04-12-2007 10:19 AM |
| Capturing shell script command output | designflaw | Shell Programming and Scripting | 2 | 03-01-2006 01:24 PM |
| Need help capturing pipe to a file in shell script | heinz | Shell Programming and Scripting | 6 | 11-03-2005 05:27 AM |
| capturing output in script | MizzGail | Shell Programming and Scripting | 6 | 06-02-2004 04:44 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Quote:
Code:
/path/to/C_exec <argc no> <argument1> <argument2> return_value=$? Last edited by vino; 05-16-2006 at 04:13 AM. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
The return status (what you want) is stored in the $? variable
Code:
/path/to/C_exec <argc no> <argument1> <argument2> retval=$? if [ $retval -eq 0 ] ; then echo "success" else echo "failure" fi |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |