Reputation: 159
I am trying to convert my bash script into a Windows batch file. It's a really simple one liner that's supposed to feed the contents of a file as arguments to script.exe
, and send the results to output.txt
.
This is the working bash script:
./script.exe $(cat input.txt) > output.txt
I know this might be bad style, but it works. The problem is, I have no idea how to do something like $()
in a windows batch file. When I use it it sends the string "$(cat input.txt)"
as the argument instead of running the command.
Upvotes: 1
Views: 5740
Reputation: 1502
This bash construct is called command substitution. Here is a great answer from @MichaelBurr.
You can get a similar functionality using cmd.exe scripts with the
for /f
command:for /f "usebackq tokens=*" %%a in (`echo Test`) do my_command %%a
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).
See also, on Superuser: Is there something like Command Substitution in WIndows CLI?
Upvotes: 3