简体   繁体   English

如何在单独的窗口中从python脚本启动子cmd终端并在其上执行脚本?

[英]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.

相关问题 从 python 脚本运行多个终端并执行命令 (Ubuntu) - Run multiple terminals from python script and execute commands (Ubuntu) 如何在 Windows 中执行 Python 脚本? - How to execute Python scripts in Windows? 如何使用python脚本启动其他python脚本并检查所有“子脚本”是否都已完成? - How to use python script to start other python scripts and check whether all “child scripts” are finished? (多线程-Python)如何创建一个运行两个脚本的脚本,我通常从两个不同的终端运行这些脚本? - (Multithreading-Python) How I can create a script that run two scripts which I usually run from two different terminals? 如何使python 3脚本从Windows 10上的.bat文件执行? - How to make python 3 scripts execute from .bat file on Windows 10? Python 运行与我的脚本不同的脚本 - Python run separate scripts from my script bash或python命令循环终端并对它们执行命令? - bash or python command to cycle through terminals and execute commands on them? 如何在单独的线程中从python脚本中启动flask应用程序? - How to start a flask app from within a python script in a separate thread? 在Windows中从cmd运行Python脚本 - Run Python script from cmd in windows 如何在 dockerfile CMD 脚本中执行 npm start - How to execute npm start within dockerfile CMD script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM