在Python中将参数传递给可执行文件

时间:2014-10-31 17:50:39

标签: python

我正在使用os.startfile('C:\\test\\sample.exe')启动该应用程序。我不想知道应用程序的退出状态,我只是想启动exe。

我需要将参数传递给像'C:\\test\\sample.exe' -color

这样的exe

请建议一种在Python中运行它的方法。

1 个答案:

答案 0 :(得分:3)

在我知道的每种情况下,您都应该使用subprocess模块而不是os.startfileos.system

import subprocess
subprocess.Popen([r'C:\test\sample.exe', '-color'])

可以,正如@Hackaholic在评论中建议的那样

import os
os.system(r'C:\test\sample.exe -color')

但这并不简单,the docs for os建议改为使用subprocess

相关问题