pipe STDERR to find...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

pipe STDERR to find...

#1 Post by catalinnc » 08 Dec 2016 13:03

hi...


how can i improve this line so i can capture the STDERR (or both STDOUT & STDERR)?
tool.exe outputs a report to STDOUT (when all is OK) and some BEWARE/WARNING/ERROR to STDERR (when something is dubious)...

Code: Select all

tool.exe some.file | find "ERROR"



respect...
_

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: pipe STDERR to find...

#2 Post by npocmaka_ » 08 Dec 2016 13:35

Code: Select all

tool.exe some.file 2>&1 | find "ERROR"

catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

Re: pipe STDERR to find...

#3 Post by catalinnc » 09 Dec 2016 13:36

npocmaka_ wrote:

Code: Select all

tool.exe some.file 2>&1 | find "ERROR"


thanks a lot...working great...
_

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: pipe STDERR to find...

#4 Post by Aacini » 09 Dec 2016 17:54

I invite you to review this related post. For example, using this test Batch file:

Code: Select all

@echo off
echo This line to Stdout
ping -n 2 -w 1 localhost > NUL
echo THIS LINE IS AN ERROR! >&2
ping -n 2 -w 1 localhost > NUL
echo This line is normal
ping -n 2 -w 1 localhost > NUL
echo Another line to Stderr >&2
ping -n 2 -w 1 localhost > NUL
echo The last normal line

... and execute it this way:

Code: Select all

"test.bat" 2>&1 1>&3 | AnsiSys.exe 4E

.. show this output:
Image

You may also use FINDSTR to mark the lines from StdErr in this simpler way:

Code: Select all

test.bat 2>&1 1>&3 | findstr /A:4E /N "^"

... but in this case just the numbers of the lines from Stderr will be displayed in other color.

Antonio

Post Reply