When working with Bash, I can put the output of one command into another command like so:
my_command `echo Test`
would be the same thing as
my_command Test
(Obviously, this is just a non-practical example.)
I'm just wondering if you can do the same thing in Batch.
You can get a similar functionality using cmd.exe scripts with the
for /f
command:Yeah, it's kinda non-obvious (to say the least), but it's what's there.
See
for /?
for the gory details.Sidenote: I thought that to use "
echo
" inside the backticks in a "for /f
" command would need to be done using "cmd.exe /c echo Test
" sinceecho
is an internal command tocmd.exe
, but it works in the more natural way. Windows batch scripts always surprise me somehow (but not usually in a good way).Maybe I'm screwing up the syntax of the standard
for /f
method, but when I put a very complex command involving && and | within the backticks in the limit of thefor /f
, it causes problems. A slight modification from the usual is possible to handle an arbitrary complexity command:By putting your full and complex command in a variable first, then putting a reference to the variable in the limit rather than putting the complex command directly into the limit of the for loop, you can avoid syntax interpretation issues. Currently if I copy the exact command I have set to the
VV
variable in the example above into where it's used,%VV%
, it causes syntax errors.Read the documentation for the "for" command:
for /?
Sadly I'm not logged in to Windows to check it myself, but I think something like this can approximate what you want:
You can do it by redirecting the output to a file first. For example:
You could always run Bash inside Windows. I do it all the time with MSYS (much more efficient than Cygwin).