如何使用python运行带有参数的exe文件 [英] how to run an exe file with the arguments using python

查看:256
本文介绍了如何使用python运行带有参数的exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Suppose I have a file RegressionSystem.exe. I want to execute this executable with a -config argument. The commandline should be like:

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() 如果你愿意.例如,

You can also use subprocess.call() if you want. For example,

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 形式.您可以在 这个问题.

The difference between call and Popen is basically that call is blocking while Popen is not, with Popen providing more general functionality. Usually call is fine for most purposes, it is essentially a convenient form of Popen. You can read more at this question.

这篇关于如何使用python运行带有参数的exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆