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" )
phuclv
43.3k16 gold badges191 silver badges559 bronze badges
asked Aug 2, 2019 at 7:00
Suji Ryali
751 gold badge2 silver badges5 bronze badges
2 Answers 2
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>")
answered Aug 2, 2019 at 8:49
Axois
2,0612 gold badges13 silver badges23 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Suji Ryali
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
Suji Ryali
Well it actually worked with code you have given. Thanks a lot :-)
you can do so using subprocess module , refer this tutorial for executing your commands.It works for windows too.
Comments
lang-py