cmd.exe launched from another cmd.exe











up vote
0
down vote

favorite












I'm doing a script that I start with bash.exe from Cygwin on Windows:



C:bash.exe my_script.sh


It changes my Python Virtual Env depending of some conditions. For those who know Virtualenv, I need to use "workon.bat" and the only way I know to execute a batch script is the following one:



...
cmd /K "workon.bat" "$required_venv"
...


It works but I'm now in a new cmd.exe instance launched from the previous one. Proof : Typing exit bring me back to it :



C:bash.exe my_script.sh  *ENTER*
(venv) C:
(venv) C:exit *ENTER*
C:


In fact, each time I will launch that script I will be in a new instance :



cmd.exe
cmd.exe
cmd.exe
cmd.exe
...


How to solve that annoying recursive situation ? One solution could be to detect that I'm in a cmd launched into another one and exit. I would be ideal to execute the batch workon.bat while remaining inside the cmd.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm doing a script that I start with bash.exe from Cygwin on Windows:



    C:bash.exe my_script.sh


    It changes my Python Virtual Env depending of some conditions. For those who know Virtualenv, I need to use "workon.bat" and the only way I know to execute a batch script is the following one:



    ...
    cmd /K "workon.bat" "$required_venv"
    ...


    It works but I'm now in a new cmd.exe instance launched from the previous one. Proof : Typing exit bring me back to it :



    C:bash.exe my_script.sh  *ENTER*
    (venv) C:
    (venv) C:exit *ENTER*
    C:


    In fact, each time I will launch that script I will be in a new instance :



    cmd.exe
    cmd.exe
    cmd.exe
    cmd.exe
    ...


    How to solve that annoying recursive situation ? One solution could be to detect that I'm in a cmd launched into another one and exit. I would be ideal to execute the batch workon.bat while remaining inside the cmd.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm doing a script that I start with bash.exe from Cygwin on Windows:



      C:bash.exe my_script.sh


      It changes my Python Virtual Env depending of some conditions. For those who know Virtualenv, I need to use "workon.bat" and the only way I know to execute a batch script is the following one:



      ...
      cmd /K "workon.bat" "$required_venv"
      ...


      It works but I'm now in a new cmd.exe instance launched from the previous one. Proof : Typing exit bring me back to it :



      C:bash.exe my_script.sh  *ENTER*
      (venv) C:
      (venv) C:exit *ENTER*
      C:


      In fact, each time I will launch that script I will be in a new instance :



      cmd.exe
      cmd.exe
      cmd.exe
      cmd.exe
      ...


      How to solve that annoying recursive situation ? One solution could be to detect that I'm in a cmd launched into another one and exit. I would be ideal to execute the batch workon.bat while remaining inside the cmd.










      share|improve this question















      I'm doing a script that I start with bash.exe from Cygwin on Windows:



      C:bash.exe my_script.sh


      It changes my Python Virtual Env depending of some conditions. For those who know Virtualenv, I need to use "workon.bat" and the only way I know to execute a batch script is the following one:



      ...
      cmd /K "workon.bat" "$required_venv"
      ...


      It works but I'm now in a new cmd.exe instance launched from the previous one. Proof : Typing exit bring me back to it :



      C:bash.exe my_script.sh  *ENTER*
      (venv) C:
      (venv) C:exit *ENTER*
      C:


      In fact, each time I will launch that script I will be in a new instance :



      cmd.exe
      cmd.exe
      cmd.exe
      cmd.exe
      ...


      How to solve that annoying recursive situation ? One solution could be to detect that I'm in a cmd launched into another one and exit. I would be ideal to execute the batch workon.bat while remaining inside the cmd.







      windows bash cmd.exe cygwin bash-scripting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 at 18:36

























      asked Nov 17 at 18:24









      snoob dogg

      1086




      1086






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          Instead of



          cmd /K "workon.bat" "$required_venv"


          Use



          cmd /C "workon.bat" "$required_venv"


          As it will close the new shell after running the batch file, from cmd /?



          /c  Carries out the command specified by String and then stops.
          /k Carries out the command specified by String and continues.





          share|improve this answer





















          • This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : (
            – snoob dogg
            Nov 17 at 19:34










          • using /c doesn't keep the virtualenv :/
            – snoob dogg
            Nov 18 at 8:46


















          up vote
          0
          down vote













          @matzeri is wrong about cmd /C as it will also close the virtualenv which is unexpected. I think that doing that job on Windows using Cygwin, Bash and script-shell was a bad idea, I ended up by doing a batch file instead.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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%2fsuperuser.com%2fquestions%2f1376283%2fcmd-exe-launched-from-another-cmd-exe%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            Instead of



            cmd /K "workon.bat" "$required_venv"


            Use



            cmd /C "workon.bat" "$required_venv"


            As it will close the new shell after running the batch file, from cmd /?



            /c  Carries out the command specified by String and then stops.
            /k Carries out the command specified by String and continues.





            share|improve this answer





















            • This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : (
              – snoob dogg
              Nov 17 at 19:34










            • using /c doesn't keep the virtualenv :/
              – snoob dogg
              Nov 18 at 8:46















            up vote
            1
            down vote













            Instead of



            cmd /K "workon.bat" "$required_venv"


            Use



            cmd /C "workon.bat" "$required_venv"


            As it will close the new shell after running the batch file, from cmd /?



            /c  Carries out the command specified by String and then stops.
            /k Carries out the command specified by String and continues.





            share|improve this answer





















            • This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : (
              – snoob dogg
              Nov 17 at 19:34










            • using /c doesn't keep the virtualenv :/
              – snoob dogg
              Nov 18 at 8:46













            up vote
            1
            down vote










            up vote
            1
            down vote









            Instead of



            cmd /K "workon.bat" "$required_venv"


            Use



            cmd /C "workon.bat" "$required_venv"


            As it will close the new shell after running the batch file, from cmd /?



            /c  Carries out the command specified by String and then stops.
            /k Carries out the command specified by String and continues.





            share|improve this answer












            Instead of



            cmd /K "workon.bat" "$required_venv"


            Use



            cmd /C "workon.bat" "$required_venv"


            As it will close the new shell after running the batch file, from cmd /?



            /c  Carries out the command specified by String and then stops.
            /k Carries out the command specified by String and continues.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 17 at 18:56









            matzeri

            1,217156




            1,217156












            • This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : (
              – snoob dogg
              Nov 17 at 19:34










            • using /c doesn't keep the virtualenv :/
              – snoob dogg
              Nov 18 at 8:46


















            • This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : (
              – snoob dogg
              Nov 17 at 19:34










            • using /c doesn't keep the virtualenv :/
              – snoob dogg
              Nov 18 at 8:46
















            This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : (
            – snoob dogg
            Nov 17 at 19:34




            This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : (
            – snoob dogg
            Nov 17 at 19:34












            using /c doesn't keep the virtualenv :/
            – snoob dogg
            Nov 18 at 8:46




            using /c doesn't keep the virtualenv :/
            – snoob dogg
            Nov 18 at 8:46












            up vote
            0
            down vote













            @matzeri is wrong about cmd /C as it will also close the virtualenv which is unexpected. I think that doing that job on Windows using Cygwin, Bash and script-shell was a bad idea, I ended up by doing a batch file instead.






            share|improve this answer

























              up vote
              0
              down vote













              @matzeri is wrong about cmd /C as it will also close the virtualenv which is unexpected. I think that doing that job on Windows using Cygwin, Bash and script-shell was a bad idea, I ended up by doing a batch file instead.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                @matzeri is wrong about cmd /C as it will also close the virtualenv which is unexpected. I think that doing that job on Windows using Cygwin, Bash and script-shell was a bad idea, I ended up by doing a batch file instead.






                share|improve this answer












                @matzeri is wrong about cmd /C as it will also close the virtualenv which is unexpected. I think that doing that job on Windows using Cygwin, Bash and script-shell was a bad idea, I ended up by doing a batch file instead.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 18 at 11:54









                snoob dogg

                1086




                1086






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376283%2fcmd-exe-launched-from-another-cmd-exe%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

                    Сан-Квентин

                    8-я гвардейская общевойсковая армия

                    Алькесар