The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-16-2006
Registered User
 

Join Date: May 2006
Posts: 6
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
Reply With Quote
Forum Sponsor
  #2  
Old 05-16-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Quote:
Originally Posted by k_bijitesh
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...
Code:
/path/to/C_exec <argc no> <argument1> <argument2>
return_value=$?

Last edited by vino; 05-16-2006 at 04:13 AM.
Reply With Quote
  #3  
Old 05-16-2006
Registered User
 

Join Date: May 2006
Posts: 101
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.
Reply With Quote
  #4  
Old 05-16-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
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
This test is for a simple 0 = success, anything else = failure
Reply With Quote
  #5  
Old 05-16-2006
Registered User
 

Join Date: May 2006
Posts: 6
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
Reply With Quote
  #6  
Old 05-16-2006
Registered User
 

Join Date: May 2006
Posts: 101
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0