Page 1 of 1

Escaping spaces when using 'run' command in script

Posted: 17 Apr 2023 12:45
by roel_v
I have the following script:

Code: Select all

  foreach($item, <get selecteditemspathnames>, <crlf>, , "No files selected!") {
      $file_path = getpathcomponent($item, "path");
      $file_base = getpathcomponent($item, "base");
      run "cmd /k ""c:\Program Files\GDAL\gdalwarp.exe"" -te -1611382 -3930115 -1176482 -3443415 -tr 100 100 ""$item"" ""$file_path\$file_base" . "_resampled_100m.tif""", , 1, 1;
  }
which just shells out a command to execute on selected files. It didn't work and the cmd.exe window just flashed so I couldn't see any error message. So I added the cmd /k in the front, and what I see is ''c:\Program' is not recognized as an internal or external command, operable program or batch file.' But I am escaping the path to the executable. I tried doubling up on the escaping and not escaping at all but neither worked. So what am I missing here?

Re: Escaping spaces when using 'run' command in script

Posted: 17 Apr 2023 13:08
by highend

Code: Select all

  foreach($item, <get selecteditemspathnames>, <crlf>, , "No files selected!") {
      $new_file = getpathcomponent($item, "path") . "\" . getpathcomponent($item, "base") . "_resampled_100m.tif";
      run """c:\Program Files\GDAL\gdalwarp.exe"" -te -1611382 -3930115 -1176482 -3443415 -tr 100 100 ""$item"" ""$new_file""", , 1, 1;
  }
?

Re: Escaping spaces when using 'run' command in script

Posted: 17 Apr 2023 13:34
by roel_v
Thanks but same result - I should maybe add that the file I'm doing this operation on is not in Program Files; maybe I'm reading it wrong but it seems your proposal only changes the quoting of the command arguments? I'm thinking it's in the way the program itself is called but maybe I'm overlooking something.

Re: Escaping spaces when using 'run' command in script

Posted: 17 Apr 2023 13:46
by highend
Select a file to transform.

Execute this, show the result.

Code: Select all

$new_file = getpathcomponent(<curitem>, "path") . "\" . getpathcomponent(<curitem>, "base") . "_resampled_100m.tif";
      text """c:\Program Files\GDAL\gdalwarp.exe"" -te -1611382 -3930115 -1176482 -3443415 -tr 100 100 ""<curitem>"" ""$new_file""";
Copy the result, execute it in a dos box and show a screenshot of the dos box afterwards