0

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.

1

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.
  • This doens't work unfortunatly because if it close the new shell, it close also the the virtual venv, right ? : ( – snoob dogg Nov 17 '18 at 19:34
  • using /c doesn't keep the virtualenv :/ – snoob dogg Nov 18 '18 at 8:46
0

@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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.