python - 在运行时将参数传递给可执行程序
问题描述
我正在使用 Python Os.System("path/xyz.exe",parameter)
exe_file = "E:\selenium-python\\autopilot.exe -config" + argument
os.system(exe_file)
上面的代码工作正常,但现在为了我的程序目的,我想在整个程序中使用这个相同的运行 .exe 文件,现在问题是我想在运行时传递参数。
python有什么办法可以解决这个问题
解决方案
您可以将配置文件名作为 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)
推荐阅读
- python-3.x - 在 Python 中使用 Selenium WebDriver 选择元素
- r - R Markdown 不为 PDF 生成参考书目
- python - 如何格式化 x 轴以显示每年的主要刻度
- qt - 如何在带有页面的 QML 中显示模型?
- html - 将容器外的图像拉伸到页面末尾。calc() 是这种布局的唯一解决方案吗?
- java - Spring Data JPA Native Query - 未注册命名参数
- webassembly - AssemblyScript 是否支持函数数组?
- java - 如何在 Java 的 for 循环中使用值?
- python - 通过单击 django 中的按钮运行批处理文件
- java - 应用程序实际使用的是这两个 java 版本中的哪一个?