这是我的代码片段:
script_dir = os.path.dirname(os.path.abspath(__file__))
subprocess.Popen(["application.exe"],cwd=script_dir, close_fds=True)
我的问题是我无法让上面的代码工作。我尝试使用我的 Python 代码运行 application.exe
但运行时没有任何反应。
我正在以类似的方式运行另一个应用程序,它可以工作:
subprocess.Popen(["binary\\application.exe"],cwd=os.path.realpath("./binary/"), env=os.environ.copy(), close_fds=True)
所以问题是,第一个子进程调用出了什么问题,我该如何解决这个问题?
最佳答案
使用 os.path.join
将第一个参数指定为绝对路径:
script_dir = os.path.dirname(os.path.abspath(__file__))
subprocess.Popen(
[os.path.join(script_dir, "application.exe")],
cwd=script_dir, close_fds=True)
关于Python 另一个应用程序启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20930712/