在子进程打开的程序关闭之前,我的代码不会继续

My code doesn't continue until the program open by subprocess is closed

我正在尝试使用 Subprocess 模块打开记事本,然后打印程序已打开。 我的代码:

import os
import subprocess
if os.path.exists(r'C:\Windows\System32\notepad.exe'):
    subprocess.run(r'C:\Windows\System32\notepad.exe')
    print('Program executed')

记事本打开,但问题是打印命令在我关闭记事本之前不起作用。有没有办法克服这个问题?

使用 Popen 代替 运行 会有所帮助。然后脚本不等待程序关闭:

subprocess.Popen(r'C:\Windows\System32\notepad.exe')