8

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:

7
  • 2
    Does it work without start? "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4 Commented Jul 16, 2013 at 10:52
  • 2
    Use call, not start, for running batch scripts from other batch scripts. Commented Jul 16, 2013 at 11:06
  • 1
    @AnsgarWiechers I was simply trying to figure whether the command works as is or not. If it didn't work as is, chances are that it wouldn't work with start or call or whatever. Commented Jul 16, 2013 at 11:15
  • 1
    @devnull It does work with call. Commented Jul 16, 2013 at 11:24
  • 1
    What if the command is not a batch script (but an .exe file)? Then CALL wont work, right? I haven't tested it but I would assume that the original question would remain even if that would be the case? Commented Jul 16, 2013 at 11:26

3 Answers 3

18

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried it about one hour ... but against a bug of course I can do nothing :)
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.
4 years later and this is still a bug... But so thanks for a very usefull answer :)
10

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

3 Comments

Sorry - I have overseen that the problem belongs to spaces in both PATH and ARGUMENTS...
That helped mine as well :D
For God's sake... I lost some time with this. It should be "start" then what I want to start.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.