Use a .bat file to open a pipenv virtual environment and then run commands

Viewed 1813

I would like create a .bat file to cd to my working directory, start a pipenv virtual environment, and then run a series of commands in the pipenv shell command prompt.

#test.bat

    cd C:\testdirectory

    pipenv shell

    echo test

My pipenv shell starts, but the "echo test" is not executed.

2 Answers

I created a batch file to take me to the correct folder and open the environment (as above) and then ran a second batch file which contains:

pipenv run python manage.py runserver

I combined Marks idea of using a second bat file. with the pipenv run command. This way you only need to run the teststart.bat file, which will execute the runtest.bat file inside the pipenv environment.

test starter bat file:

C:\Users\Me\Desktop\teststart.bat
    cd C:\Users\Me\my_project
    pipenv run runtest // all commands in the runtest.bat file will be inside pipenv

test runner bat file:

C:\Users\Me\my_project\runtest.bat
     echo test
     echo 'more comamnds'
     python manage.py runserver
Related