How to feed a file into a program that reads stdin (on Windows command line)

command line

I have a program P that processes stdin. How can I feed a file into this program from the windows command line?

P < filename

does not work.

filename | P
filename > P

does not work either.

edit

tried again, in fact

P < filename

or

grep abc < lab.txt

does work. Thank you for the participation.

Best Answer

I tried this script that set the contents of the filename as variable "a" and then fed this variable "a" as an argument to the "p" program.

@echo off
for /f "tokens=1 delims={" %%a in ('TYPE filename ^| FINDstr /r "[a-z]"') do (cmd /c p "%%a")
pause

Note that this script has a number of limitations as I used regular expression in findstr command supposing that the contents of filename is just text. I don't know what your filename contents are so you have to modify it to suites your needs. Also you need to modify your program "p" so that it accepts arguments. Hope this help.

Related Question