LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-22-2004, 01:06 PM   #1
naflan
Member
 
Registered: May 2003
Location: NC, USA
Distribution: Slackware 14.0
Posts: 94

Rep: Reputation: 15
exit status


I have a C application that returns a value to the shell.

Code:
exit(status);
I can get this value from the shell by using

echo $?

but, when I use it in the following way, I always get 0 even when status is not 0:

c_app | mutt -s "$?" email.address

mutt is a mail program, -s "subject line"

What is overwriting $? ?
 
Old 10-22-2004, 01:14 PM   #2
avarus
Member
 
Registered: Apr 2004
Location: Oxford, UK
Distribution: Ubuntu, Debian, various
Posts: 230
Blog Entries: 5

Rep: Reputation: 33
Hi Naflan,

You actually have two problems here. The first is that $? is evaluated by the shell before it even thinks about running your program.

The second is that mutt is actually started before c_app finishes, such is the nature of piped execution, so mutt could never get the return value of c_app anyway.

As far as I can tell the only simple way to do what you want is to use an intermediate file for the output, then invoke mutt on the next line to read the file back, but maybe there is a more cunning solution.

TIM
 
Old 10-22-2004, 01:22 PM   #3
naflan
Member
 
Registered: May 2003
Location: NC, USA
Distribution: Slackware 14.0
Posts: 94

Original Poster
Rep: Reputation: 15
Thanks Avarus,
I thought that I would have to do this with a script.
1. c_app > temp.txt
2. capture $? in a variable.
3. Run mutt using the variable in my subject line.
mutt -s "$variable" email@address.com < temp.txt


Quote:
The second is that mutt is actually started before c_app finishes, such is the nature of piped execution, so mutt could never get the return value of c_app anyway
I had not thought of it this way. Thanks

naflan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
> Ftp With Exit Status, Ftp with exit status vwvr9 Linux - General 4 02-23-2005 03:53 AM
exit status 17 kppp joshy Mandriva 3 10-08-2004 08:07 AM
error exit status 30 debian_dummy Debian 2 09-21-2004 11:26 PM
gcc exit status 1 Daddio Linux - Software 4 10-25-2003 06:37 PM
Trapping an exit status chrisk5527 Linux - General 3 09-12-2003 10:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration