Capturing a ret val of C obj file in ksh script


 
Thread Tools Search this Thread
Top Forums Programming Capturing a ret val of C obj file in ksh script
# 1  
Old 05-16-2006
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
# 2  
Old 05-16-2006
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 08:13 AM..
# 3  
Old 05-16-2006
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  
Old 05-16-2006
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
# 5  
Old 05-16-2006
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  
Old 05-16-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stripping ret of the lines in a file (sed question)

Hi all, I didn't use SED for 20 years and was never an expert. So my current knowledge is about zero. Please be patient with me. I'm neither a native speaker. I have a huge dictionary file and want the rest of the lines stripped. Everything after (and including) the "/" should be stripped. I... (2 Replies)
Discussion started by: Hinnerk2005
2 Replies

2. Shell Programming and Scripting

Capture a database val and use in script

Hello, sorry if this has been asked before, I couldn't find what I was looking for. I know how to connect to Oracle and execute stored procedures from a shell script, but what I would like to do is return a value from a table and use it in my script. For Example, If I had a table Called... (1 Reply)
Discussion started by: mode09
1 Replies

3. Solaris

SunONE (webserver7) obj.conf

Hello all, I'm configuring the webserver and I need to add some parameters to be logged, so I don't know if I'm doing it right, please advice. Here's my obj.conf: # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # You can edit this... (0 Replies)
Discussion started by: TorvusBog
0 Replies

4. Shell Programming and Scripting

Use of "@ ret =" in sh script

I've been thrown into debugging a sh script and have run into an unfamiliar bit of code. In part the code is: set ret = 1 set roop = 0 while( $ret == 1 ) @ ret = `rcp chPhase.dat.default "$remoteUser@$ENGINE_HOST\:/gp/tune/chPhase.dat"$remoteUser@$ENGINE_HOST\:/gp/tune/chPhase.dat`... (3 Replies)
Discussion started by: Stmpjmp
3 Replies

5. Shell Programming and Scripting

Capturing stderr in ksh script within a script

I have seen lots of entries on stderr and stdout, but I did not see a solution to my question. In running a script, I call another script. I want to capture output and error messages from the called script. I am able to redirect the stdout from the called script to my output file, but I don't... (2 Replies)
Discussion started by: timtoben
2 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. UNIX for Dummies Questions & Answers

make command failed for target 'obj/gp_unix.o'

hi, i am trying to run make command in solaris 9. its giving the error: make:Fatal error:Command failed for target 'obj/gp_unix.o' i came to know X11 should be inastalled for gp_unix.o.But it is already installed.still the same error. ./configure worked fine. can anybody please suggest... (3 Replies)
Discussion started by: rosalina
3 Replies

8. Shell Programming and Scripting

capturing line from script output and appending to a file

Hi all, I did some searching in this forum but can't find anything that matches the issue I'm bumping heads with. On a CentOS4/Postfix (and bash everywhere) mail gateway box I run a command periodically to purge the Postfix queue of messages "From:MAILER-DAEMON". This is the one line'r... (6 Replies)
Discussion started by: wally_welder
6 Replies

9. Shell Programming and Scripting

Need help capturing pipe to a file in shell script

The command: echo "this is some text" | shellscript abc def ghi My problem: How to capture "this is some text" so that I can process it, I.e. capture to a file. What I'm attemting to do is process the text echo'd into a file after writing the parameters passed first. No problem... (6 Replies)
Discussion started by: heinz
6 Replies

10. Shell Programming and Scripting

ret val of a command in a pipe which is NOT the last one

hello dear UNIX gurus ;-) my problem is one of those i would think that many others should also have had it in the past. but i cannot find any thread or other documentation about it. inside a ksh script i have a pipe like this: ksh -c "export LIBPATH=$LD_LIBRARY_PATH; ${Cmd} ${Param} 2>&1... (5 Replies)
Discussion started by: latze
5 Replies
Login or Register to Ask a Question