0

I'm trying to make a script for me that activates a virtual environment, install requirements and start a Python server.

My script looks like this:

@echo off cmd /k "cd /d C:\Users\evaknid\venv\Scripts & activate & pip install -r reqs.txt" @echo off cmd /k "cd /d C:\Users\evaknid\rm_analytics\developer-management-tool & python manage.py runserver" 

My problem is that the script only runs the first part each time and don't go to the other one which would start the server.

What mistake have I made?

I run this on a windows 7 machine and use the cmd to run the script if it helps.

3 Answers 3

4

I don't see a need to create a new cmd.exe instance, or any need to join your commands on the same line:

@PushD "C:\Users\evaknid\venv\Scripts" @Call "activate.bat" @PIP install -r reqs.txt @PushD "..\..\rm_analytics\developer-management-tool" @python manage.py runserver @PopD @PopD 

The bottom two lines are probably optional, (can be removed if you're not continuing the script beyond those commands).

It may not even be necessary to be jumping in and out of directories, simply using similar syntax to this, Call "C:\Users\evaknid\venv\Scripts\activate.bat", may work equally as well in your environment.

Sign up to request clarification or add additional context in comments.

Comments

2

the 'cmd' command invokes a new command-line each time it is called. So you are basically creating two seperate instances of the commandline with these two calls.

If you call the bat file from within a fresh cmdline you dont need the cmd /k

@echo off cd /d C:\Users\evaknid\venv\Scripts & activate & pip install -r reqs.txt cd /d C:\Users\evaknid\rm_analytics developer-management-tool python manage.py runserver 

the /d is actually optional, since you don't change drives. Whether you & the commands together or not is up to you.

robvanderwoude.com is a nice resource, if you have trouble with batch file commands

5 Comments

Thanks for the comment and explanation. But when I try your suggestion I still get stuck after the first command. It starts the virtualenv and install the reqs, but wont cd and run server.
Well, one solution is to omit the cmd /k completely, instead opening a blank commandline and calling this batchfile from there. (I updated the answer for this)
Thanks for the help Dan. Your solution also works, but posted how I solve the problem here also.
You should mark yours as the answer then, so its closed
To low rep, so can't do that until 2 days. WIll comeback and do that
1

After some testing I found a solution to my problem:

@echo off cmd /k "cd /d C:\Users\evaknid\venv\Scripts & activate & pip install -r reqs.txt & cd /d C:\Users\evaknid\rm_analytics\developer-management-tool & python manage.py runserver" 

The comment made by Dan help me to understand that I don't need to create two instances.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.