real windows equivalent to cat *stdin*

someprog | findstr x* or any other single character followed by asterisk copies all lines from the pipe stdin to stdout. Specifically, it copies each line if it either does contain an x or doesn't, which you can easily see is always true. Windows findstr is roughly equivalent to Unix grep but with annoying minor differences in the syntax.

findstr is intended for text and I'm not sure (and didn't test) if it works for binary data with few or no [CR]LFs and therefore very long apparent lines. Unix cat with no args does work for binary, but your stated use case is programs that alter their output for pipes and in my experience that only happens on text output -- and usually is not pipes as such but rather NON-tty/NON-console/etc and therefore I can test equally well with someprog >temp; cat temp on Unix or & type on Windows unless the program is interactive and I need to see one output before entering the next input.


TLDR: findstr "^" > STDIN.txt as the first line in your .bat will neatly capture all piped input for later use.

I discovered that the first line/command/program in a batch file gets STDIN so I took the following approach:

  1. Capture STDIN to a file STDIN.txt
  2. Code your .bat logic
  3. Use TYPE STDIN.txt to access or pipe your STDIN on to further programs

Example:

fawk.bat:

@ECHO OFF
:: Capture STDIN initially as the first line of our .bat
FINDSTR "^" > STDIN.txt

:: Do some other stuff here

:: Pipe STDIN on to our program here (e.g. find all .txt files)
TYPE STDIN.txt | AWK /\.txt$/

:: Cleanup
DEL /Q STDIN.txt

Usage:

C:>DIR /b | fawk.bat
a.txt
file.txt
README.txt

Tags:

Pipe

Cmd.Exe