如何利用Python调用带参数的exe

前言

在实际生产生活中,常常用到别人封装好的exe,如果有一堆文件要处理,全靠手动输入的话,岂不是浪费时间。本篇博文将简单介绍下如何用python调用exe。

exe文件架构

主要用到的有exe和config这两个文件,如下图所示:
在这里插入图片描述

代码

主要流程就是,先传参,再调用exe

import os
import glob
import subprocess

def polygonize(imagePath, raster_path, forest_shp_path, pwd):
    # pwd = ''
    os.chdir(os.path.realpath(os.path.join(pwd,'polygonize/')))
    polygonize_exe = os.path.realpath(os.path.join(pwd,'polygonize/polygonize0529.exe'))
    polygonize_path = os.path.realpath(os.path.join(pwd,'polygonize/polygonize.config'))
    rmHole = "100"
    simpoly = "4"
    scale = "3"
    with open(polygonize_path,'w') as f_config:
        f_config.write("--image=" + imagePath+'\n')
        f_config.write("--edgebuf="+raster_path+'\n')
        f_config.write("--line="+forest_shp_path+'\n')
        f_config.write("--rmHole=" + rmHole + '\n')
        f_config.write("--simpoly=" + simpoly + '\n')
        f_config.write("--scale=" + scale)
    f_config.close()
    subprocess.call(polygonize_exe)

猜你喜欢

转载自blog.csdn.net/weixin_42990464/article/details/112246143