Skip to content

Commit

Permalink
autotest: fix execution of commands on Windows with backslashes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Jul 19, 2023
1 parent 632e271 commit a32e4ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 8 additions & 2 deletions autotest/pymod/gdaltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,10 @@ def runexternal(
encoding="latin1",
):
# pylint: disable=unused-argument
command = shlex.split(cmd)
if sys.platform == "win32":
command = cmd
else:
command = shlex.split(cmd)
if strin is None:
p = subprocess.Popen(command, stdout=subprocess.PIPE)
else:
Expand Down Expand Up @@ -1949,7 +1952,10 @@ def _read_in_thread(f, q):

def runexternal_out_and_err(cmd, check_memleak=True, encoding="ascii"):
# pylint: disable=unused-argument
command = shlex.split(cmd)
if sys.platform == "win32":
command = cmd
else:
command = shlex.split(cmd)
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if p.stdout is not None:
Expand Down
4 changes: 3 additions & 1 deletion autotest/pyscripts/test_gdal_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def test_gdal_edit_py_3(script_path):
shutil.copy(test_py_scripts.get_data_path("gcore") + "byte.tif", filename)

try:
test_py_scripts.run_py_script(script_path, "gdal_edit", filename + " -a_srs ''")
test_py_scripts.run_py_script(
script_path, "gdal_edit", filename + " -a_srs None"
)

ds = gdal.Open(filename)
wkt = ds.GetProjectionRef()
Expand Down
11 changes: 5 additions & 6 deletions autotest/utilities/test_gdal_rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,11 @@ def test_gdal_rasterize_7(gdal_rasterize_path, sql_in_file):
else:
sql = '"' + sql + '"'
cmds = (
"""tmp/test_gdal_rasterize_7.csv
tmp/test_gdal_rasterize_7.tif
-init 0 -burn 1
-sql %s
-dialect sqlite -tr 1 1 -te -1 -1 51 51"""
% sql
"tmp/test_gdal_rasterize_7.csv "
+ "tmp/test_gdal_rasterize_7.tif "
+ "-init 0 -burn 1 "
+ f"-sql {sql} "
+ "-dialect sqlite -tr 1 1 -te -1 -1 51 51"
)

gdaltest.runexternal(gdal_rasterize_path + " " + cmds)
Expand Down

0 comments on commit a32e4ff

Please sign in to comment.