0

I would like the file to open command prompt and execute two simple commands, however the file only runs the first command - changing the directory. Manually I would type the cd command and then on the new line that appears, type the python command.

start cmd /k cd "C:\Users\PS\Documents\django_project"
& echo run cmd /k python manage.py runserver 0.0.0.0:8000

I've tried all combinations of &, &&, CALL, echo, run cmd, cmd

3
  • 2
    I'm not sure why you are running a batch file, (in cmd.exe) and from it opening two more cmd.exe instances! Does Start "test" /D "%UserProfile%\Documents\django_project" "P:\athTo\python.exe" manage.py runserver 0.0.0.0:8000 not achieve what you wanted? Commented Feb 6, 2023 at 16:21
  • That may just be my mistake however the python command does not work, I believe because I have multiple versions installed. Commented Feb 6, 2023 at 19:08
  • The P:\athTo\ part of my advice is specifically to prevent such things from causing you an issue. You use the path to the version of python you need! Commented Feb 6, 2023 at 19:33

1 Answer 1

1

This is a CMD issue. Enclose everything after the /k in quotes:

start cmd /k "cd C:\Users\PS\Documents\django_project & echo run cmd /k python manage.py runserver 0.0.0.0:8000"

It might get tricky if further quotes are needed 'inside' of the outside quotes.

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

2 Comments

Unfortunately the command line now shows a text string print of 'run cmd /k python manage.py runserver', followed by a new line showing the new directory (due to the successfully executed cd command). I've also tried with quotes inside.
Well, that is what the line says "echo...". If you need the the python script to run in the said directory, then remove "echo run cmd /k "

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.