How to get return value from C program and logs to file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to get return value from C program and logs to file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-05-2008
yhacks yhacks is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 1 October 2008, 7:57 AM EDT
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
How to get return value from C program and logs to file

Hi, I have written scritp which prints output from the executable to standard output as well as in a file. Here "add" is an c executable which returns
some value based on inputs.

But if tee is not used "$?" returns the return value from add exe.
If tee is used it is simply retuning 0.

echo "Running program output"
myLine="./add 1 11"
`expr "$myLine"`| tee outputfile
echo "Succ/Fail : $?"
Sponsored Links
    #2  
Old 03-05-2008
sjday sjday is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 21 May 2008, 6:43 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
try this

you need to look at the system variable $PIPESTATUS

echo "Running program output"
myLine="./add 1 11"
`expr "$myLine"`| tee outputfile
echo "Succ/Fail : $PIPESTATUS"
Sponsored Links
    #3  
Old 03-06-2008
yhacks yhacks is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 1 October 2008, 7:57 AM EDT
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Bug $PIPESTATUS not printing any value

echo "Running program output"
myLine="./add 1 11"
`expr "$myLine"`| tee outputfile
echo "Pass / Fail : $PIPESTATUS"

Thanks for your reply.
$PIPESTATUS is not printing any value when it is written in script
    #4  
Old 03-11-2008
yhacks yhacks is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 1 October 2008, 7:57 AM EDT
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Getting return value with logs

Please help me out
Sponsored Links
    #5  
Old 03-11-2008
kunnilmanvya kunnilmanvya is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 24 March 2008, 3:56 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hammer & Screwdriver Is this u need....try this

echo "Running program output"
myLine="./add 1 11"
`expr "$myLine"` > outputfile
echo "Succ/Fail:$?"
Sponsored Links
    #6  
Old 03-14-2008
yhacks yhacks is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 1 October 2008, 7:57 AM EDT
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Output from executable

Want to print output from the exe to file and terminal at a time.
So, used `tee` command. But return status of tee is printed instead of
exe return value.
Can use pipestatus. pipestatus is printing value but need to run like "bash script.sh". I need to run the script using "sh".
Help needed.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Program: How to FTP logs from a Server to Desktop rymnd_12345 UNIX for Dummies Questions & Answers 2 12-09-2011 12:10 PM
Parallel Processing Detection and Program Return Value Detection azar.zorn Programming 4 07-01-2011 06:13 PM
Trapping program return code pavlosgr Shell Programming and Scripting 5 01-28-2011 01:44 AM
How to capture C program return values in Kshell jclanc8 Shell Programming and Scripting 2 11-16-2010 04:56 PM
Grep yesterday logs from weblogic logs harish.parker Shell Programming and Scripting 3 11-04-2008 08:00 AM



All times are GMT -4. The time now is 10:58 AM.