I want to run an executable program which resides in a directory below my script path. The path contains spaces and one the program arguments requires double quotes.
This seems to be a composite of other questions already asked here (Handling directories with spaces Python subprocess.call(), Passing double quote shell commands in python to subprocess.Popen()?) but none of them provided a proper solution for my problem.
Here is my code:
import subprocess
subdir = 'ogr\\'
command = subdir + 'ogr2ogr.exe -f "ESRI Shapefile" output0.shp input0.kml'
output,error = subprocess.Popen(
command, universal_newlines=True, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
The executable which I am trying to run (ogr2ogr.exe) resides o in a "ogr\" subdirectory below my script, which in turn is in a directory containing spaces (eg., C:\My Documents\My Apps\Scripts\myscript.py). One of its parameters require double quotes. The above commands handle the double quotes in the arguments and work well if I put the script and the input file (input0.kml) in the same subdirectory of the executable, but fail with the message "The system cannot find the specified file" if I attempt to run it in the same directory of the script itself.
Any hints?
Thanks in advance!