Why does windows START command not work with spaces in arguments AND path?

18,372

Solution 1

It's a known bug of the START command.
If you have spaces in both, the command and of the parameters and try to handle them with quotes, it fails.

First the START command check if the full command exists.
But then it starts only the first part.

In your case it looks for "C:\tmp\test runner2.bat" but try to start C:\tmp\test.

You can avoid it when the command is replaced by a CALL

START /b /wait "Dummy title" CALL "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4

The START uses cmd /k to start the new process.
And that is the cause for the misbehaviour.
Paul Groke mentioned the fact, that this only occours when it's a batch file.
Exe files will be executed directly and so they are not affected by the cmd.exe bug.

In your case

C:\Windows\system32\cmd.exe  /K "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4

And the help of cmd /k and cmd /c explains, that in this case the first and last quote are removed.

Solution 2

"Jeb" already pointed into the right direction. In my case i didn't tried to run a batch, but a program in the "Program Files" folder (batch shall terminate after launching the program). When calling

START "C:\Program Files\MyAppPath\MyApp.exe" arg1 arg2 ... argN

the path typed with quotes around is supposed to be the "Title" parameter by START command. To get rid of that, you have to "fake" a window title like that:

START "" "C:\Program Files\MyAppPath\MyApp.exe" arg1 arg2 ... argN

This helped in my case.

Solution 3

This does not answer my question, but it does solve the immediate problem I'm having.

While reading through the "Problem with quotes around file names in Windows command shell"-post I discovered a workaround:

cmd.exe /C ""C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4"

There is also the other workaround by simply executing the command with the call command instead (as stated by Ansgar Wiechers)

call "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4
Share:
18,372
A. Nilsson
Author by

A. Nilsson

Updated on July 28, 2022

Comments

  • A. Nilsson
    A. Nilsson almost 2 years

    This command works

    START /b /wait "Dummy title" "C:\tmp\test runner2.bat" arg1 arg2
    

    But both of these fails!

    START /b /wait "Dummy title" "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4
    START /b /wait "Dummy title" "C:\tmp\test runner2.bat" arg1 arg2 "arg 3"
    

    The error is:

    'C:\tmp\test' is not recognized as an internal or external command, operable program or batch file.
    

    Obviously it has something to do with " surounding the arguments, but why and how do I work around this?

    Related questions:

  • Endoro
    Endoro almost 11 years
    I tried it about one hour ... but against a bug of course I can do nothing :)
  • Willy K.
    Willy K. over 9 years
    Sorry - I have overseen that the problem belongs to spaces in both PATH and ARGUMENTS...
  • Max
    Max almost 9 years
    That helped mine as well :D
  • Paul Groke
    Paul Groke over 8 years
    This only seems to happen if start is used to execute a batch file. If start is used to start a .exe, this problem does not occur.
  • MartinJH
    MartinJH over 6 years
    4 years later and this is still a bug... But so thanks for a very usefull answer :)
  • Miguel Angelo
    Miguel Angelo almost 4 years
    For God's sake... I lost some time with this. It should be "start" then what I want to start.