2

I am trying to start cmd window and then running a chain of cmds in succession one after the other in that cmd window. something like start cmd /k pipenv shell && py manage.py runserver the start cmd should open a new cmd window, which actually happens, then the pipenv shell should start a virtual environment within that cmd instance, also happens, and the py manage.py runserver should run in the created environment but instead it runs where the script is called.

Any ideas on how I can make this work?

3
  • A simple caret solves this start cmd /k pipenv shell && py manage.py runserverstart cmd /k pipenv shell ^&^& py manage.py runserver , but it's easier to use a batch file Commented Sep 15, 2019 at 7:23
  • the caret seems not change anything Commented Sep 15, 2019 at 7:46
  • 1
    I missed the first &&, it should be cmd /k pipenv shell ^&^& py manage.py runserverstart cmd /k pipenv shell ^&^& py manage.py runserver Commented Sep 15, 2019 at 8:10

2 Answers 2

2

When issuing commands chaining them, the system sees it as first command && second command

I your case, you are giving first command to be start cmd and second command py manage.py which will do exactly that, you are issuing a cmd in a new window and if that is successful, it will initiate py in the same window you started. You should therefore escape the & with a caret in order to pass through the chain to the second command window and not initiate the chain in the current window:

start cmd /k pipenv shell ^&^& py manage.py runserver

Keep in mind that you could also just add both commands into a batch file as:

pipenv shell
py manage.py runserver

and launch it as:

start "" mybatch.cmd
Sign up to request clarification or add additional context in comments.

Comments

1

Your py manage.py runserver command calling python executor in your major environment. In your case, you could use pipenv run manage.py runserver that detect your virtual env inside your pipfile and activate it to run your command. An alternative way is to use virtualenv that create virtual env directly inside your project directory and calling envname\Scripts\activate each time you want to run something inside your virtual env.

1 Comment

removes the need to run two successive commands, that's y I have voted you up though it does not solve my problem of wanting to run successive scripts in opened cmd, I have other cmds commands i want to run in succession other than the virtual environment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.