SOLVED: Advanced shell scripting question :-)

2002-09-06 Thread Steven W. Orr

On Wed, 4 Sep 2002, Steven W. Orr wrote:

=I have a program (which we shall call p) which produces text to both 
=stdout and stderr.
=
=I want the following three things to happen when I run p:
=
=1. I want both stdout and stderr to go to the screen
=
=2. I want stdout and stderr combined in a file
=
=3. I want an error log file to only contain stderr.
=
=p 21 | tee outnerr # Solves 1 and 2
=
=p 2 errlog   # Solves 3 but breaks 1 and 2
=
=p 2 errlog | tee out # Solves 3 but also breaks 1 and 2.
=
=Any takers?
All kinds of fun games have been played, but I now have
GermanAccentZe Final Solution/GermanAccent.

{
p 21 3 3- | tee err
} 31 | tee out

[This was so elegant I almost cried when I saw it.]

But! This still suffers slightly from the buffering problem we were 
looking at that also turned out to be part of the problem. To fix that, I 
took a look at the unbuffer command which comes with the expect package. I 
modified it so it would not do the unbuffering that it was designed for. 
Instead, it now does straight line buffering.

(The line buffering was turned off by virtue of running through a pipe.)

Here is the new lbuffer command:

#!/usr/bin/expect --
eval spawn $argv
set timeout -1
expect

So the total solution is this:

{
lbuffer p 21 3 3- | tee err
} 31 | tee out

Thanks to everyone :-)

You may now talk amongst yourselves.

-- 
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question? [EMAIL PROTECTED]

___
gnhlug-discuss mailing list
[EMAIL PROTECTED]
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss



Re: SOLVED: Advanced shell scripting question :-)

2002-09-06 Thread Bob Bell

On Fri, Sep 06, 2002 at 09:44:53AM -0400, Steven W. Orr [EMAIL PROTECTED] wrote:
 {
 p 21 3 3- | tee err
 } 31 | tee out
 
 [This was so elegant I almost cried when I saw it.]

What is the '3-' for?  I can't seem seem to find what '-' means,
plus it runs the same with or without this argument for me.

 {
 lbuffer p 21 3 3- | tee err
 } 31 | tee out

When I run this on my Tru64 box at work or on my Linux box at home
(which seems to be so underpowered that it doesn't have the
lines-out-of-order problem), I get an empty 'err' file.  Does this work
for everybody else?

BTW, Steven, you might want to consider changing 'spawn' to 'spawn
-noecho'.

I must say, though, the expect fakeout to get rid of buffering is
pretty cool...

-- 
Bob Bell [EMAIL PROTECTED]
-
 Everything that can be invented has been invented.
   -- Commissioner, US Office of Patents, 1889
___
gnhlug-discuss mailing list
[EMAIL PROTECTED]
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss