如何使用2个参数多次调用一个exe(每次都需要修改1个)

How to call an exe multiple times with 2 arguments (1 needs to be modified each time)

我正在尝试编写一个 python 程序,它将接收一个包含一堆图像的目录,然后在该图像上运行一个 exe 并将其放入一个新目录中。在命令行上,exe 通过调用 ./exe arg1 arg2 来工作。 Arg1 是源图像,arg2 是应该放在新目录中的新输出图像的名称。这是我目前拥有的:

image_files = glob.glob('path/to/source/dir')
output_directory = 'path/to/output/dir'
for image in image_files:
    # run through exe
    subprocess.run(['exe', image, output_directory])

当 运行 程序显示“没有这样的文件或目录:'exe'”时,我也遇到错误,而我的 exe 与我的 [=16= 位于同一文件夹中] 脚本。但是,该 exe 没有扩展名 .exe。有什么帮助吗?

确保您有扩展名和 ./:

subprocess.run(['./myfile.exe', image, output_directory])

如果仍然无法正常工作,请使用 os.getcwd() 检查它实际上是 python 正在工作的同一目录。