Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In linux, this takes one command, and passes its output (stdout) to another:

echo `ls`

What is the Windows/cmd/batch equivalent?

share|improve this question
up vote 6 down vote accepted

cmd.exe offers a rudimentary command substitution facility using backticks, but only via the for loop with the /f usebackq option. It's pretty brain-dead compared to what a Unix shell would do, however, as its standard behavior is to pick up only the first word of each line of output from the child and only so you can iterate over them, not so you can paste all of them at once onto the command line. (You can adjust the behavior somewhat with the delims option.) Here's an example:

for /f usebackq %F in (`dir /w s*c`) do echo %F

If you want genuine Unix-style command substitution, you'll need a genuine Unix shell, e.g., either Cygwin bash or my own (commercial) Hamilton C shell.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.