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
Share:
6,450

Related videos on Youtube

Jichao
Author by

Jichao

Full stack hello world developer

Updated on September 18, 2022

Comments

  • Jichao
    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
    Jichao almost 12 years
    what does &1 means?
  • martineau
    martineau almost 12 years
    To 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
    beppe9000 about 4 years
    @martineau are there other handles or can handles be created by windows api ?
  • martineau
    martineau about 4 years
    @beppe9000: Standard input (stdin), standard output (stdout) and standard error (stderr) are the ony ones standardized. The values 0, 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 Windows cmd console or the MS C runtime library supports them or not.