How to pipeline stderr in cmd.exe?
6,450
You can redirect stderr to stdout by using 2>&1
, and then pipe stdout into grep
.
So, what I think you want is this:
xx /? 2>&1 | grep regex
Related videos on Youtube
Comments
-
Jichao over 1 year
Some programs would prefer to output the help message in stderr. I want to search the help message with
grep
command,xx /? | grep regex
?How could i do this?
-
Jichao almost 12 yearswhat does &1 means?
-
martineau almost 12 yearsTo specify redirection to existing handles, use the ampersand
&
character followed by the handle number that you want to redirect (that is,&handle#
). stdin is handle #0, stdout is handle #1, and stderr is handle #2. -
beppe9000 about 4 years@martineau are there other handles or can handles be created by windows api ?
-
martineau about 4 years@beppe9000: Standard input (
stdin
), standard output (stdout
) and standard error (stderr
) are the ony ones standardized. The values0
,1
, &2
, correspond to the C language Unix OS "file descriptors", so in theory there could be other numbers — however I don't know if the Windowscmd
console or the MS C runtime library supports them or not.