[英]Software launched with os.system or subprocess.Popopen closes as python shuts down
I am trying to launch an android emulator from Python.我正在尝试从 Python 启动一个 android 模拟器。 I have tried the following code:
我尝试了以下代码:
os.system('C:\\Nox\\bin\\Nox.exe -clone:Nox')
subprocess.Popopen('C:\\Nox\\bin\\Nox.exe -clone:Nox')
The emulator launched by either code closes as soon as python code is terminated.一旦 python 代码终止,由任一代码启动的模拟器就会关闭。 However, when I run the code (
'C:\\\\Nox\\\\bin\\\\Nox.exe -clone:Nox'
) in Win10 terminal, the emulator doesn't close when the terminal is closed.但是,当我在 Win10 终端中运行代码(
'C:\\\\Nox\\\\bin\\\\Nox.exe -clone:Nox'
)时,终端关闭时模拟器不会关闭。
How can I keep the emulator running when python code terminates? python 代码终止时如何保持模拟器运行? I do not want to keep python code running.
我不想让 python 代码运行。
I don't have a Windows machine to try this on, but in Ubuntu the following did it for me:我没有 Windows 机器来尝试这个,但在 Ubuntu 中,以下为我做了:
import subprocess
subprocess.Popen('<your command string>', shell=True)
So in your case:所以在你的情况下:
import subprocess
subprocess.Popen('C:\\Nox\\bin\\Nox.exe -clone:Nox', shell=True)
Note there is a parameter creationFlags with values that seem of interest ( https://docs.python.org/3/library/subprocess.html#windows-constants ), however hopefully shell=True will suffice.请注意,有一个参数 creationFlags 的值似乎很有趣( https://docs.python.org/3/library/subprocess.html#windows-constants ),但希望 shell=True 就足够了。
Do note the strong warnings in the documentation around opening a process with shell=True where the process being run depends upon some user input!请注意文档中关于使用 shell=True 打开进程的强烈警告,其中正在运行的进程取决于某些用户输入!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.