Replacement for $() in Windows batch script
up vote
-1
down vote
favorite
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.
bash batch-file
add a comment |
up vote
-1
down vote
favorite
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.
bash batch-file
1
If the unknown windows script.exe accepts redirected input, eithertype input.txt|script.exe >output.txt
orscript.exe <input.txt >output.txt
otherwise you can have bash through wsl or a similar syntax with powershell.
– LotPings
Nov 11 at 23:28
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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.
bash batch-file
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.
bash batch-file
bash batch-file
asked Nov 11 at 22:26
mrFoobles
776
776
1
If the unknown windows script.exe accepts redirected input, eithertype input.txt|script.exe >output.txt
orscript.exe <input.txt >output.txt
otherwise you can have bash through wsl or a similar syntax with powershell.
– LotPings
Nov 11 at 23:28
add a comment |
1
If the unknown windows script.exe accepts redirected input, eithertype input.txt|script.exe >output.txt
orscript.exe <input.txt >output.txt
otherwise you can have bash through wsl or a similar syntax with powershell.
– LotPings
Nov 11 at 23:28
1
1
If the unknown windows script.exe accepts redirected input, either
type input.txt|script.exe >output.txt
or script.exe <input.txt >output.txt
otherwise you can have bash through wsl or a similar syntax with powershell.– LotPings
Nov 11 at 23:28
If the unknown windows script.exe accepts redirected input, either
type input.txt|script.exe >output.txt
or script.exe <input.txt >output.txt
otherwise you can have bash through wsl or a similar syntax with powershell.– LotPings
Nov 11 at 23:28
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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
" since
Testecho
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?
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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
" since
Testecho
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?
add a comment |
up vote
1
down vote
accepted
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
" since
Testecho
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?
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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
" since
Testecho
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?
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
" since
Testecho
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?
answered Nov 12 at 2:10
Mathieu CAROFF
3367
3367
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253864%2freplacement-for-in-windows-batch-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If the unknown windows script.exe accepts redirected input, either
type input.txt|script.exe >output.txt
orscript.exe <input.txt >output.txt
otherwise you can have bash through wsl or a similar syntax with powershell.– LotPings
Nov 11 at 23:28