[英]How to start child cmd terminals in separate windows, from python script and execute scripts on them?
I have been trying rather unsuccesfully to open several terminals (though one would be enough to start with) from say an ipython terminal that executes my main python script. 我一直在尝试从执行我的主要python脚本的ipython终端打开多个终端(尽管足以开始使用),但一直没有成功。 I would like this main python script to open as many cmd terminals as needed and execute a specific python script on each of them. 我希望这个主要的python脚本根据需要打开尽可能多的cmd终端,并在每个终端上执行特定的python脚本。 I need the terminal windows to remain open when the script finishes. 脚本完成后,我需要终端窗口保持打开状态。
I can manage to start one terminal using the command: 我可以使用以下命令来启动一个终端:
import os
os.startfile('cmd')
but I don't know how to pass arguments to it, like: 但我不知道如何将参数传递给它,例如:
/K python myscript.py
Does anyone have any ideas on how this could be done? 有谁对如何实现有任何想法?
Cheers HH 干杯
Use subprocess module. 使用子流程模块。 Se more info at. Se的更多信息。 Google>>python subprocess Google >> python子进程
http://docs.python.org/2/library/subprocess.html http://docs.python.org/2/library/subprocess.html
import subprocess
subprocess.check_output(["python", "c:\home\user\script.py"])
or 要么
subprocess.call(["python", "c:\home\user\script.py"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.