FANDOM


When passing filenames to programs using runCommand or runCommandInBg, it is important to put quotation marks around filenames with spaces or other special characters. You can use the following function to put double-quotes (") around your filenames before passing them in a runCommand string.

function quoteFilename(str)
{
  return "\"" + str.replace(/[\\"]/g, "\\$&") + "\"";
}


ExampleEdit

This will start Adobe Reader 7.0 on Windows:

var path = "C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32.exe";
runCommand("start " + quoteFilename(path));