I have this simple batch script. Lets call it 'Hello World.bat':

echo "Hello World!"

In a command line, running

cmd /c start "C:\path\to\Hello World.bat"

causes the a new command line window to show up, but the code in the .bat file is not executed.

I can rename this bat file to Hello_World.bat, remove the quotes from the command line command, and it works fine. However, with the quotes (which are necessary due to the spaces), it will not work.

Any suggestions? The application I'm working on calls customer-placed batch files, so unfortunately just renaming it isn't an option.

  • Does it have to open in a new CMD window?
    – Tim G.
    Sep 8 '16 at 19:00

The Start command actually requires you to put in a title parameter like this:

start ["<Title>"] [/d <Path>]

You can get around this by adding an empty " " before the path to your file, like this:

cmd start "" /c "C:\path\to\Hello World.bat"
  • Interesting. It appears that "cmd start /c "C:\path\to\Hello World.bat" does what I want as well. Why does this work, and what I had originally does not work? Edit: Well, actually it doesn't work through command line, but it does in my Java code... one sec. Sep 8 '16 at 19:18
  • I ended up going with this. It seems a bit strange that the ordering of the /c parameter changes the behavior of the command so much, and I still don't quite understand, but thank you for pointing me in the right direction. Sep 8 '16 at 19:33
  • 2
    Small correction: "According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted." - so the advice is always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes "". See start
    – DavidPostill
    Sep 8 '16 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.