Skip to Content.
Sympa Menu

sm-sorcery-bugs - [SM-Sorcery-Bugs] [Bug 7201] New: kyle's > $C_FIFO doesn't work and is wrong for our needs

sm-sorcery-bugs AT lists.ibiblio.org

Subject: Bugs for Sorcery are reported here

List archive

Chronological Thread  
  • From: bugzilla-daemon AT metalab.unc.edu
  • To: sm-sorcery-bugs AT lists.ibiblio.org
  • Subject: [SM-Sorcery-Bugs] [Bug 7201] New: kyle's > $C_FIFO doesn't work and is wrong for our needs
  • Date: Mon, 2 Aug 2004 14:15:33 -0400

http://bugs.sourcemage.org/show_bug.cgi?id=7201

Summary: kyle's > $C_FIFO doesn't work and is wrong for our needs
Product: Sorcery
Version: Devel
Platform: Other
OS/Version: other
Status: NEW
Severity: normal
Priority: P2
Component: subroutines
AssignedTo: sm-sorcery-bugs AT lists.ibiblio.org
ReportedBy: seth AT tautology.org


Currently we needed the ability to read stderr but ' > $C_FIFO 2>&1 ' merged
data destined for fd 2 into fd 1 by duplicating the output fd 2 as output fd
1.

The solution to remove 2>&1 is broken. Why? Now compile logs won't have
stderr
in them. That's kind of limiting for debugging. Bash is able to do what we
want, and without the FIFO and the backgrounded process reading the FIFO.
Let's
dump both.

Currently we do something like this:

export C_LOG=/tmp/1and2.log
export C_FIFO=/tmp/1and2.fifo
mkfifo C_FIFO 2> /dev/null
rm $C_LOG 2> /dev/null
cat $C_FIFO > $C_LOG &
(
(
echo 1
sleep 1
echo 2 1>&2
sleep 1
echo 1-2
sleep 1
echo 2-2 1>&2
exit 1 # to prove later on that return codes don't mangle
) > $C_FIFO
) && echo madeit #proves return codes don't mangle

But this works a lot better and doesn't require bash3:

export C_LOG=/tmp/1and2.log
rm $C_LOG 2> /dev/null
(
(
echo 1
sleep 1
echo 2 1>&2
sleep 1
echo 1-2
sleep 1
echo 2-2 1>&2
exit 1 # to prove later on that return codes don't mangle
) 2> >(tee -a $C_LOG 1>&2) > >(tee -a $C_LOG)
) && echo madeit #proves return codes don't mangle


allow me to explain '2> >(tee -a $C_LOG 1>&2) > >(tee -a $C_LOG)':

2> >(tee -a $C_LOG 1>&2) # redirect stderr data into an out-of-band pipe with
stderr on stdin where tee takes stdin and outputs appended to the log and
stdout
and 1>&2 directs stdin back to stderr where we want it.
> >(tee -a $C_LOG) # redirects stdout data into an out-of-band pipe with stdin
on tee, tee writing to the log appended and outputting also to stdout again
which is already where we want it.

By doing it out-of-band and not using '|' for an in-band pipe, the return
value
after the out-of-band pipe is the return value of the subshell it is acting
upon, not the return value of the last item in the pipe, which is what happens
on in-band pipes.

Now a cast blah > /tmp/superdebug.out behaves as appropriate since stderr is
always stderr in the end _and_ the compile logs have both stdout and stderr
properly interleaved as we want.



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



  • [SM-Sorcery-Bugs] [Bug 7201] New: kyle's > $C_FIFO doesn't work and is wrong for our needs, bugzilla-daemon, 08/02/2004

Archive powered by MHonArc 2.6.24.

Top of Page