How to handle files with spaces in batch scripts?

I am creating a batch file to execute few programs but having trouble with pro gra mme.exe. The script gets stuck on

cd "C:\Program Files (x86)\Dir 1\Main"
start "pro gra mme.exe"

While executing I am getting prompt with C:\Program Files (x86)\Dir 1\Main>. What could be the problem? I am adding using double quotes in start "pro gra mme.exe" to counter the spaces.


I am adding using double quotes in start "pro gra mme.exe" to counter the spaces

Please read the help for start.

Syntax

  START "title" [/D path] [options] "command" [parameters]

In your case "pro gra mme.exe" is being interpreted by the cmd shell as the title.

You can use the following command instead:

start "" "pro gra mme.exe"

Note:

Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes ""

According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted.

Source - start


Further Reading

  • An A-Z Index of the Windows CMD command line
  • A categorized list of Windows CMD commands
  • start - Start a program, command or batch script (opens in a new window).