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

2024-04-01

假设我有一个文件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() http://docs.python.org/2/library/subprocess.html#using-the-subprocess-module如果你想。例如,

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)

和...之间的不同call and Popen基本上就是这样call正在阻塞,而Popen不是,与Popen提供更通用的功能。通常call对于大多数用途来说都很好,它本质上是一种方便的形式Popen。您可以阅读更多内容这个问题 https://stackoverflow.com/questions/7681715/whats-the-difference-between-subprocess-popen-and-call-how-do-you-use-them-to.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 python 运行带参数的 exe 文件 的相关文章

随机推荐