V
V
Vova2017-03-24 12:38:42
cmd/bat
Vova, 2017-03-24 12:38:42

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

1 answer(s)
A
Alexander, 2017-03-24
@NeiroNx

redirect output to file then from file to variable

dir /b| find ".bat" > tmp
SET /P TMPS=<tmp
del tmp
type %TMPS%
pause

you can still use FOR as it accepts output
the only difference is that in the first case, the variable will contain the entire file, and FOR will break it line by line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question