Here is a batch script:
Z:
cd Z:\different_directory
pipenv shell
cd ..\another_directory
:End
cmd /k
What happens here is that the pipenv shell gets launched, but the virtual environment does not cd. Instead, once I exit the pipenv, it then runs the cd command.
Is it possible to run a command from inside the pipenv using this batch script?
I know this question is old but if any of you found this through google, here's the exact answer: Just use pipenv shell "/c command [args]"
, in this case pipenv shell "/c cd ..\another_directory"
Why this works: Like the documentation says, whatever comes after shell will be passed as an argument to the subshell, and the argument /c on CMD runs a command on shell spawn. So there. You could even make it run a whole .bat.
You can use pipenv run
instead of pipenv shell
to directly run a python command or a batch script. You won't be able to run pipenv run cd ../another_dir
directly, but I'm assuming that isn't the main goal of this since you'd only be changing the directory in that session. You can create a batch script, say test.bat, with
cd ../another_dir
python test.py
Then run it with pipenv run test.bat
. The page below has more details.
source: http://witkowskibartosz.com/blog/pipenv_run_vs_pipenv_shell.html#.W2SBZflKhaQ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With