I want to run an executable and display its contents. Sometimes the
contents include the word "ERROR". I want to be able to run the
program, show all the contents, then see if the word Error is there. I
could do
program > somefile 2>&1
cat file
if [ -z `grep ERROR somefile` ] ; then
echo "An error occurred"
exit 1
fi
but that would not show the contents until after I'd run the program.
I'd like to show all the contents as the prgram runs, then afterwards
grep for the word ERROR.
I thought I could do this with "tee", but I don't seem to be getting
anywhere.
Any suggestions?
|
|
0
|
|
|
|
Reply
|
Dr
|
9/6/2010 8:19:50 AM |
|
On Mon, 6 Sep 2010 01:19:50 -0700 (PDT) "Dr. David Kirkby"
<david.kirkby@onetel.net> wrote:
> I want to run an executable and display its contents. Sometimes the
> contents include the word "ERROR". I want to be able to run the
> program, show all the contents, then see if the word Error is there. I
> could do
>
> program > somefile 2>&1
> cat file
> if [ -z `grep ERROR somefile` ] ; then
> echo "An error occurred"
> exit 1
> fi
>
> but that would not show the contents until after I'd run the program.
> I'd like to show all the contents as the prgram runs, then afterwards
> grep for the word ERROR.
>
> I thought I could do this with "tee", but I don't seem to be getting
> anywhere.
It's not clear what you want to see with tee, but assuming you want to see
both output and errors (ie the same things that will go into "somefile"),
then try
program 2>&1 | tee somefile
|
|
0
|
|
|
|
Reply
|
pk
|
9/6/2010 8:34:58 AM
|
|
On Mon, 06 Sep 2010 01:19:50 -0700, Dr. David Kirkby wrote:
> I want to run an executable and display its contents. Sometimes the
> contents include the word "ERROR". I want to be able to run the program,
> show all the contents, then see if the word Error is there. I could do
>
> program > somefile 2>&1
> cat file
> if [ -z `grep ERROR somefile` ] ; then
> echo "An error occurred"
> exit 1
> fi
>
> but that would not show the contents until after I'd run the program.
> I'd like to show all the contents as the prgram runs, then afterwards
> grep for the word ERROR.
>
> I thought I could do this with "tee", but I don't seem to be getting
> anywhere.
>
> Any suggestions?
The "obvious" thing is
program | tee somefile
if grep ERROR somefile >/dev/null
then
# rm somefile
echo An error occurred
exit 1
fi
# rm somefile
If you have enough supporting structure then
exec 3>&1 # Make fd 3 a copy of stdout
if program | tee /dev/fd/3 | grep ERROR >/dev/null
then
echo An error occurred
exit 1
fi
assuming that you do not want the information saved in a file.
Depending on your grep, you may be able to use 'grep -q ...' instead of
'grep ... >/dev/null', but I would tend to use the latter for portability.
|
|
0
|
|
|
|
Reply
|
Icarus
|
9/6/2010 6:02:07 PM
|
|
|
2 Replies
396 Views
(page loaded in 0.057 seconds)
Similiar Articles: Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ...Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ... nohup, redirection and splitting stderr and stdout - comp.unix ... Redirect stderr/stdout to a file ... question about execl(), fork(), stdin, stdout, stderr - comp.unix ...... with stdin, stdout and stderr ... the saved file. The problem is that this external program prints stuff to the STDOUT/STDERR and ... 1); /* copy reading end to stdout ... How to test if stdout == stderr? - comp.unix.programmerHi! In a C program (Mac OSX Darwin/BSD), I'd like to check whether stdout and stderr are pointing to the same file. When stdout and stderr are point... cron continues to email when no stdout/stderr from script - comp ...Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ... Redirect AT command Output to a File - comp.sys.hp.hpux cron continues to email when no stdout/stderr ... nohup, redirection and splitting stderr and stdout - comp.unix ...Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ... nohup, redirection and splitting stderr and stdout - comp.unix ... Redirect stderr/stdout to a file ... Write to stderr? - comp.lang.rexxRedirect stderr/stdout to a file using SetStdHandle - comp.os.ms ... how to write .test file using tcltest - comp.lang.tcl How to test if stdout == stderr? - comp.unix ... Capture the stdout of another process. - comp.unix.programmer ...Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ... Capture the stdout of another process. - comp.unix.programmer ... Redirect stderr/stdout to a file ... Append both standard output and standard error of command to file ...Is it possible to redirect stdout and stderr to a file? Please show me how it works. Thank you Georg ... create tar from stdin - comp.unix.adminSimple shell Script to copy file from one location to another ... question about execl(), fork(), stdin, stdout, stderr ... Tar transfer and delete files - comp.unix ... how to suppress error messages being outputted to the screen ...If you want to keep the stdout being put to the screen, and only stderr to a file, I think you should use: $ command 2> myfile.log You could also have stdout be ... stdin, stdout, stderr - Microsoft Corporation: Software ...Copy. FILE *stdin; FILE *stdout; FILE *stderr; #include <stdio.h> Redirect to STDOUT and fileI am trying to redirect STDOUT and STDERR to a file as well as to STDOUT or STDERR (depending on ... create a real (system) file handle, neither the original nor the copy can ... 7/24/2012 6:05:33 AM
|