1

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.

1
  • 3
    If by "DOS" one means "cmd.exe in Windows", then consider PowerShell as a modern alternative to that relic. Likewise, consider one of the several "Unix util" ports. FWIW, there are some really old program for MS-DOS as well, such as Unix-like MS-DOS programs Commented May 9, 2011 at 20:48

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.