简体   繁体   English

如何在python中打开一个exe文件并继续而不关闭exe文件?

[英]How to open an exe file in python and continue without close exe file?

I wrote this code:我写了这段代码:

import subprocess

subprocess.call(["notepad.exe"], creationflags=subprocess.CREATE_NEW_CONSOLE)
print('I continue working.')

but until i close notepad my script won't continue running.但在我关闭记事本之前,我的脚本不会继续运行。 How to open file and continue running script without closing this file?如何在不关闭此文件的情况下打开文件并继续运行脚本?

For that you use the subprocess.Popen method like this:为此,您可以使用subprocess.Popen方法,如下所示:

process = subprocess.Popen("notepad.exe", shell=True, stdin=subprocess.PIPE)

You might want to read about pipes and delve deeper into the subprocess module, in case you want to interact in any way with the processes you call using that function.如果您想以任何方式与使用该函数调用的进程进行交互,您可能需要阅读有关管道的信息并深入研究子流程模块。

Related question: How to start a background process in Python?相关问题: 如何在 Python 中启动后台进程?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM