Préface
Dans la production et la vie réelles, l'exe empaqueté par d'autres est souvent utilisé. S'il y a un tas de fichiers à traiter, qui reposent tous sur une saisie manuelle, c'est une perte de temps. Cet article de blog présentera brièvement comment appeler exe avec python.
structure de fichier exe
Les deux fichiers principalement utilisés sont exe et config, comme le montre la figure ci-dessous:
Code
Le processus principal consiste à passer d'abord les paramètres, puis à appeler 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)