Escaping spaces when using 'run' command in script

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
roel_v
Posts: 24
Joined: 13 Jul 2014 12:39

Escaping spaces when using 'run' command in script

Post 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?

highend
Posts: 14925
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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;
  }
?
One of my scripts helped you out? Please donate via Paypal

roel_v
Posts: 24
Joined: 13 Jul 2014 12:39

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

Post 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.

highend
Posts: 14925
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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
One of my scripts helped you out? Please donate via Paypal

Post Reply