Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • How to create batch file in Windows using “start” with a path and command with spaces
  • Can I use the “start” command with spaces in the path?
like image 485
A. Nilsson Avatar asked Jul 16 '13 10:07

A. Nilsson


2 Answers

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.

like image 199
jeb Avatar answered Nov 28 '22 15:11

jeb


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

like image 27
Willy K. Avatar answered Nov 28 '22 13:11

Willy K.