Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 01:10 PM
Parallel Processing Detection and Program Return Value Detection azar.zorn Programming 4 07-01-2011 07:13 PM
Trapping program return code pavlosgr Shell Programming and Scripting 5 01-28-2011 02:44 AM
How to capture C program return values in Kshell jclanc8 Shell Programming and Scripting 2 11-16-2010 05:56 PM
Grep yesterday logs from weblogic logs harish.parker Shell Programming and Scripting 3 11-04-2008 09:00 AM



All times are GMT -4. The time now is 09:50 PM.