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.










share|improve this question


















  • 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

















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.










share|improve this question


















  • 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















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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 22:26









mrFoobles

776




776








  • 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
















  • 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










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














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
Test
" since echo is an internal command to cmd.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?






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    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
    Test
    " since echo is an internal command to cmd.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?






    share|improve this answer

























      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
      Test
      " since echo is an internal command to cmd.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?






      share|improve this answer























        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
        Test
        " since echo is an internal command to cmd.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?






        share|improve this answer












        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
        " since echo is an internal command to cmd.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?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 2:10









        Mathieu CAROFF

        3367




        3367






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine