Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!bu.edu!orc!inews!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: Return values in pipelines Message-ID: <1990Aug23.215612.12422@iwarp.intel.com> Date: 23 Aug 90 21:56:12 GMT References: <1990Aug22.211057.19850@agate.berkeley.edu> <7372@star.cs.vu.nl> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 37 In-Reply-To: maart@cs.vu.nl (Maarten Litmaath) In article <7372@star.cs.vu.nl>, maart@cs (Maarten Litmaath) writes: | In article <1990Aug22.211057.19850@agate.berkeley.edu>, | ) How can I detect if something went wrong on the previous | )commands in the pipeline (prog2, prog3)? | | You can do something like this: [program using fd 3 and /bin/sh fd duping deleted] Hmm. Similar to what I was going to do, except that I would have used temp files (remember... a temp file is just a pipe with an attitude and a strong will to live). #!/bin/sh trap "rm /tmp/r$$.*; exit" 0 1 2 3 15 rm -f /tmp/r$$.? (A || echo A exited with $? >/tmp/r$$.A) | (B || echo B exited with $? >/tmp/r$$.B) | (C || echo C exited with $? >/tmp/r$$.C) | (D || echo D exited with $? >/tmp/r$$.D) case /tmp/r$$.? in /tmp/r$$.\?) exit 0;; *) cat /tmp/r$$.?; exit 1;; esac With temp files, you won't get a race condition if both processes decide to exit at *exactly* the same time (rare, but it'll happen!). Just another /bin/sh hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/