Answer the question
In order to leave comments, you need to log in
How to redirect output of one command to _argument_ of another command?
Hello.
I'm a little confused :)
Usually, OS (DOS, win) uses (probably) two options for input data for programs.
1. the program expects input (for example, more)
2. the program reads command line arguments (type)
There is a pipeline that is convenient to use with type 1.
For example, type <text file> | more will perfectly transfer all the text from one program to another.
You can even use redirection: more <text file
Actually, the question is: what if I want to use a pipeline / redirection, but the program (for example, type) only supports command line arguments and does not accept normal input in any way?
For example, I want to find all the .bat files in a folder and display them on the screen.
Writing:
dir /b | find ".bat" | type
And, of course, nothing works.
Because type expects to be given an argument. Not "input".
Question: how to cram "input" into some argument, and do it inside the cmd | bat file? Is it possible?
(Well, type can be fooled by fixing the file name. But what if you need to pass an arbitrary string?)
Answer the question
In order to leave comments, you need to log in
redirect output to file then from file to variable
dir /b| find ".bat" > tmp
SET /P TMPS=<tmp
del tmp
type %TMPS%
pause
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question