Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch: launch pipenv shell, then run command in the virtual environment

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?

like image 715
Daniel Paczuski Bak Avatar asked Jul 11 '18 17:07

Daniel Paczuski Bak


2 Answers

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.

like image 23
Raff.run Avatar answered Oct 10 '22 13:10

Raff.run


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

like image 172
Amy Simmons Avatar answered Oct 10 '22 14:10

Amy Simmons