Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 4 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

 
discard

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.