Using command output in DOS
I would like to run a command in DOS, which uses the output of another command as its part, something that single back-quote (``) allows to do on UNIX or Linux.
For example, if myCommand
returns a list of files, I would like to execute in DOS some analog of the UNIX command
grep `myCommand`
How would one do that in DOS? Thank you in advance for your 开发者_开发知识库help.
You can pipe two commands:
command1 | command2
But there aren't a whole lot of commands whos input/ouput plays well with each other. You'd probably be best off using a for loop. The basic syntax is:
for /f %A in ('command1') do command2 %A
Unless you try the for %%i in ... syntax, I do not see a hope in DOS. DOS is not Unix.
Another solution is to build a new batch using the for loop (with @ and echo) and start the new batch at the end.
You may need to do this recursively.
精彩评论