首页 > 解决方案 > 在运行时将参数传递给可执行程序

问题描述

我正在使用 Python Os.System("path/xyz.exe",parameter)

    exe_file = "E:\selenium-python\\autopilot.exe -config" + argument
    os.system(exe_file)

上面的代码工作正常,但现在为了我的程序目的,我想在整个程序中使用这个相同的运行 .exe 文件,现在问题是我想在运行时传递参数。

python有什么办法可以解决这个问题

标签: pythonseleniumselenium-webdriverselenium-firefoxdriver

解决方案


您可以将配置文件名作为 Python 脚本的命令行参数传递:

import argparse

parser = argparse.ArgumentParser(description='test')
parser.add_argument('--config', help='autopilot config file')
args = parser.parse_args()

exe_file = "E:\selenium-python\\autopilot.exe -config" + args.config
os.system(exe_file)

推荐阅读