Preface
In actual production and life, the exe packaged by others is often used. If there are a bunch of files to be processed, all of which rely on manual input, is it a waste of time. This blog post will briefly introduce how to call exe with python.
exe file structure
The two files mainly used are exe and config, as shown in the following figure:
Code
The main process is to pass parameters first, then call 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)