![](/img/trans.png)
[英]Python: Unable to open a new command prompt session and run a program through command line (windows) using Python script
[英]How to open a command prompt along with a command to run using a python script?
import subprocess
cmd = subprocess.Popen('cmd.exe /K cd /')
#subprocess.Popen('cmd.exe /K netstat') # run cmd commands like netstat,..etc
#subprocess.Popen('cmd.exe /K python') # open cmd in Python live interpreter mode
#subprocess.Popen('cmd.exe /K my_script.py') # run your python script
了解更多https://docs.python.org/3/library/subprocess.html#subprocess.Popen
CMD窗口將運行您提供的命令,然后在完成后立即關閉,如果要保持窗口打開,則需要發送一個暫停命令:
os.system(“您的命令”)
os.system(“暫停”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.