5

How can I open command prompt with specific directory using Python?

I could just run command prompt using Python but I'm unable to open with specific directory.

import os
os.system("start cmd")
1
  • 1
    cmd can take arguments (run cmd /? to see them) you can do cmd /K cd c:/ to start cmd at c: Commented Aug 1, 2019 at 10:48

1 Answer 1

7

You can open the specific path using this

import os
os.system("start cmd /K cd C:\\Users\\Name\\Desktop\\File" )
Sign up to request clarification or add additional context in comments.

6 Comments

Great thanks a lot. Now I have to execute the below command using python. Could you please help with the flow py <filename> –V <variant string> -p <path to the flash files>
@SujiRyali What exactly are you trying to achieve? Are you trying to get the version of python?
no I have to flash the component. For which I am opening command prompt with specific directory using python. and then execute flashing command next an extension to opening CMD py <filename> –V <variant string> -p <path>
@SujiRyali You can change your working directory to the desired path and then input the call. I have answered your other question.
If I would like to open the command prompt in the directory where I run the python script that opens the command prompt is. How could I write the syntax after cd...?
|

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.