1

Execute CMD Command in python after opening CMD with specific directory

Opening CMD with specific directory using python. In the same sequence, have to execute below CMD Command using python.

Step 2 :

py <filename> –V <variant string> -p <path to the flash files>

Step 1 :

import os
os.system("start cmd /K cd C:\\Users\\Desktop\\Folder\\File" )

2 Answers 2

5

What you can do is that you have to change your working directory first before executing the code.

import os

os.chdir('C:\\Users\\Name\\Desktop\\testing')
os.system("start cmd /K py <filename> –V <variant string> -p <path to the flash files>")
Sign up to request clarification or add additional context in comments.

3 Comments

Thank You :-) But flashing didn't start. May be it's due to, not opening CMD as Administrator. How to modify script to run CMD as administrator and execute files
@SujiRyali you can probably take a look at this. I am not really familiar with ctypes and the whole windows thing, so I'm afraid i cant help much.
Well it actually worked with code you have given. Thanks a lot :-)
0

you can do so using subprocess module , refer this tutorial for executing your commands.It works for windows too.

Comments

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.