1

I try this batch

start cmd.exe /k "C:\Program Files (x86)\QGIS 2.18\OSGeo4W.bat" ogr2ogr.exe  -f "PostgreSQL" PG:"host=10.210.1.32 user=eric_plassot dbname=activite schemas=activite password=mdp" -t_srs EPSG:2154 -append -nlt PROMOTE_TO_MULTI "C:\Users\eplassot\toto.kml"

and get this error

C: \ Program' is not recognized...

What can I do?

ericire
  • 409
  • 6
  • 22
  • 2
    Possible duplicate of [correct quoting for cmd.exe for multiple arguments](https://stackoverflow.com/questions/12891383/correct-quoting-for-cmd-exe-for-multiple-arguments) – Cellcon Jun 20 '17 at 12:58

3 Answers3

1

Because you are using multiple quotes, it is syntactically unclear where nested quotes begin. Try this:

start cmd.exe /k ""C:\Program Files (x86)\QGIS 2.18\OSGeo4W.bat" ogr2ogr.exe  -f "PostgreSQL" PG:"host=10.210.1.32 user=eric_plassot dbname=activite schemas=activite password=mdp" -t_srs EPSG:2154 -append -nlt PROMOTE_TO_MULTI "C:\Users\eplassot\toto.kml""
Regejok
  • 436
  • 2
  • 5
  • helloThis causes the cmd.exe to be looped – ericire Jun 20 '17 at 14:42
  • So that if I paste the command "C: \ Program Files (x86) \ QGIS 2.18 \ OSGeo4W.bat" ogr2ogr.exe -f "PostgreSQL" PG: "host = 10.210.1.32 user = eric_plassot dbname = activity schemas = = Mdp "-t_srs EPSG: 2154 -append -nlt PROMOTE_TO_MULTI" C: \ Users \ eplassot \ toto.kml "in the command window it works – ericire Jun 20 '17 at 14:44
  • Does your code actually contain those spaces before and after each backslash? Basically you need to quote every single argument with spaces, the path to the executable and at the end the whole thing after `cmd /k`. – Regejok Jun 20 '17 at 15:13
  • If you paste the code I have included in my answer, it should work. – Regejok Jun 21 '17 at 06:34
  • no it doesn't the command is repeats itself several times without success the first batch call others batches – ericire Jun 21 '17 at 07:06
  • Are you sure the command works on its own? try `"C:\Program Files (x86)\QGIS 2.18\OSGeo4W.bat" ogr2ogr.exe -f "PostgreSQL" PG:"host=10.210.1.32 user=eric_plassot dbname=activite schemas=activite password=mdp" -t_srs EPSG:2154 -append -nlt PROMOTE_TO_MULTI "C:\Users\eplassot\toto.kml"` – Regejok Jun 21 '17 at 07:08
  • No it does not work A console opens with the command that repeats quickly and ends without success – ericire Jun 21 '17 at 07:20
  • But if I manually open a console and paste this command it works. I do not understand why – ericire Jun 21 '17 at 07:21
  • Did you by any chance name the script to execute this `start cmd /k` command "OSGeo4W.bat"? The only reason I can think of for it to loop is that it calls itself over and over. – Regejok Jun 21 '17 at 07:29
  • No I named it otherwise – ericire Jun 21 '17 at 07:34
  • 1
    ok, I changed the name of the bat ( before it was cmd.bat) and it works now thanks a lot – ericire Jun 21 '17 at 07:54
  • 1
    Word of advice: Don't name your scripts identical to any commands. – Regejok Jun 21 '17 at 07:59
1
  1. start might interpret the first quoted argument as a window title, so explicitly provide one (maybe even an empty one, like "") to avoid troubles.
  2. cmd /K consumes the leading and trailing quotation marks, so the remaining command line appears invalid. To avoid that, enclose the whole command line to call in "". To avoid need of escaping the command line, escape the outer-most quotes instead:

    start "" cmd.exe /K ^""C:\Program Files (x86)\QGIS 2.18\OSGeo4W.bat" ogr2ogr.exe  -f "PostgreSQL" PG:"host=10.210.1.32 user=eric_plassot dbname=activite schemas=activite password=mdp" -t_srs EPSG:2154 -append -nlt PROMOTE_TO_MULTI "C:\Users\eplassot\toto.kml"^"
    
aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • hello The same result as with the double quotes: the command repeats itself to infinity. If I do cd C:\Users\eplassot then paste this code "C:\Program Files (x86)\QGIS 2.18\OSGeo4W.bat" ogr2ogr.exe -f "PostgreSQL" PG:"host=10.210.1.32 user=eric_plassot dbname=activite schemas=activite password=mdp" -t_srs EPSG:2154 -append -nlt PROMOTE_TO_MULTI "C:\Users\eplassot\toto.kml" it works And I can not reproduce it in batch – ericire Jun 21 '17 at 06:39
  • Sorry, I can't follow; there is no loop, and I can't see what's inside of the batch file `OSGeo4W.bat`, so impossible to tell for me... – aschipfl Jun 21 '17 at 15:00
0

the first batch called is

@echo off

rem Root OSGEO4W home dir to the same directory this script exists in set OSGEO4W_ROOT=%~dp0 rem Convert double backslashes to single set OSGEO4W_ROOT=%OSGEO4W_ROOT:\=\% echo. & echo OSGEO4W home is %OSGEO4W_ROOT% & echo.

set PATH=%OSGEO4W_ROOT%\bin;%PATH%

rem Add application-specific environment settings for %%f in ("%OSGEO4W_ROOT%\etc\ini*.bat") do call "%%f"

rem List available o4w programs rem but only if osgeo4w called without parameters @echo on @if [%1]==[] (echo run o-help for a list of available commands & cmd.exe /k) else (cmd /c "%*")

ericire
  • 409
  • 6
  • 22