1

If I execute this script in windows with x86 Python, works just fine. Also from command line directly.

import os, subprocess

gm = os.path.join('C:\\', 'Program Files (x86)', 'GDAL', 'gdal_merge.py')

merge_command = ["python", gm, "-o", "C:\\temp\\merge2.asc", "C:\\temp\\507.asc", "C:\\temp\\508.asc"]

subprocess.call(merge_command, shell=True)

However, in another machine, with windows and python x64, command line tool works, but the python script does not (it only differs from the previous one in the program files directory where gdal_merge.py is located).

import os, subprocess

gm = os.path.join('C:\\', 'Program Files', 'GDAL', 'gdal_merge.py')

merge_command = ["python", gm, "-o", "C:\\temp\\merge2.asc", "C:\\temp\\507.asc", "C:\\temp\\508.asc"]

subprocess.call(merge_command, shell=True)

What could be happening? Can anyone help?

  • What's the error? Note that gdal_edit.py is written in such a way that you could import it directly from your script, then call it's main() function with the arguments. – mikewatt Jul 27 '18 at 19:47
  • Actually, it doesnt't show any error, it seems to process fine, but not operation is actually done. I tried importing gdal_merge, but it says I have no module named as such (I have installed Python, GDAL and GDAL python bindings) – Symbionte Jul 27 '18 at 19:49
  • Maybe try subprocess.check_call() or subprocess.check_output() – mikewatt Jul 27 '18 at 19:51
  • Apparently I get some error or non-zero exit code. subprocess.check_call(merge_command, shell=True) Traceback (most recent call last): File "<interactive input>", line 1, in <module> File "C:\Python27\lib\subprocess.py", line 190, in check_call raise CalledProcessError(retcode, cmd) CalledProcessError: Command '['python', 'C:\\Program Files\\GDAL\\gdal_merge.py', '-o', 'C:\\temp\\merge2.asc', 'C:\\temp\\507.asc', 'C:\\temp\\508.asc']' returned non-zero exit status 1 – Symbionte Jul 27 '18 at 22:26
0

I was able to make it work under python 32 bits, while in 64 bits, with their respective GDALs, it didnt work. May be some bug, I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.