gpt4 book ai didi

python - 如何使用python运行带有参数的exe文件

转载 作者:太空狗 更新时间:2023-10-29 16:54:49 25 4
gpt4 key购买 nike

假设我有一个文件 RegressionSystem.exe。我想用 -config 参数执行这个可执行文件。命令行应该是这样的:

RegressionSystem.exe -config filename

我试过这样的:

regression_exe_path = os.path.join(get_path_for_regression,'Debug','RegressionSystem.exe')
config = os.path.join(get_path_for_regression,'config.ini')
subprocess.Popen(args=[regression_exe_path,'-config', config])

但是没用。

最佳答案

您还可以使用 subprocess.call()如果你想。例如,

import subprocess
FNULL = open(os.devnull, 'w') #use this if you want to suppress output to stdout from the subprocess
filename = "my_file.dat"
args = "RegressionSystem.exe -config " + filename
subprocess.call(args, stdout=FNULL, stderr=FNULL, shell=False)

callPopen 的区别基本上是 call 是阻塞的,而 Popen 不是,Popen 提供更通用的功能。通常 call 适合大多数用途,它本质上是 Popen 的一种方便形式。您可以在 this question 阅读更多内容.

关于python - 如何使用python运行带有参数的exe文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15928956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com