LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 09-12-2011, 06:25 AM   #1
acc_Wk
LQ Newbie
 
Registered: Jul 2011
Posts: 18

Rep: Reputation: Disabled
Exit status of a piped-background process...


Hello I'm running into a problem while trying to collect the exit status of a command which is executed in background and which also is part of a piped set of commands..
For examples if 'a' and 'b' are commands, I'm running a | b &
And i need to get exit status of 'a'

My code snippet is shown below:
Code:
a.sh | tee -a $logfile &
wait $!
<now how do i get return status of a.sh>
PIPESTATUS[] didnt work and I also read in bash ref manual that it works only on foreground pipes... And doing $? after wait command is not returning me the status of a.sh.. I guess it would return exit-status of last command in pipe...


Any help is appreciated
Thanks for your time!!!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-12-2011, 06:49 AM   #2
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
It’s possible to catch the return code in a subshell:
Code:
(a.sh; echo $? > RETURN_CODE) | tee -a $logfile &
Then you can get the exit code from the created file.

Last edited by Reuti; 09-12-2011 at 09:29 AM. Reason: Removed awkward typo
 
2 members found this post helpful.
Old 09-12-2011, 09:26 AM   #3
acc_Wk
LQ Newbie
 
Registered: Jul 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thanks a lot !! That worked well!!
 
  


Reply



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
[SOLVED] Best way to gracefully exit a background process? robertH Programming 1 06-07-2011 08:32 AM
Capturing the exit status of the script running in background paragkalra Programming 7 04-11-2010 01:00 PM
Problem with Postfix (process smtpd exit status 1) breiko Linux - Server 18 03-26-2008 02:02 PM
getting the exit status of a background processes gururaj Linux - General 7 04-27-2006 05:56 PM
Bash - background process and exit ?? michael_util Programming 4 01-05-2005 11:03 AM

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

All times are GMT -5. The time now is 06:38 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
Open Source Consulting | Domain Registration