0

I know, I know. That way madness lies.

The title refers to this great answer. I would just like to settle, once and for all, whether or not it actually is possible to do something like this:

cmd /C start c:\program files            (says "Windows cannot find c:\program)
cmd /C "start c:\program files"          (ditto)
cmd /C start "c:\program files"          (opens another command window)
cmd /C start \"c:\program files\"        (says "Windows cannot find \"c:\program files\")
cmd /C "start \"c:\program files\""      (ditto)
cmd /C "start ^"c:\program files^""      (opens another command window)
rem Ad nauseam.

All I want to do is launch a folder or url that may have spaces in the name. Is this "advanced"?

I have seen this question, but \" is not working in the above.

I am calling this from a WScript.Shell object in VFP, so I have to pass the entire command as a single string. But I'd like to settle the more general question for reference.

Community
  • 1
  • 1
harpo
  • 41,820
  • 13
  • 96
  • 131
  • I've fought this battle before and decided that it has always been easier and less fault-prone to put such things into (perhaps temporary) files and pipe those in as inputs, even if it involves scp/rsync-ing those files to other places. – Jason Dunkelberger Jun 29 '12 at 16:34
  • @JasonD, thanks, I've considered that (or an environment variable). Glad to know it wasn't too crazy for someone else, because I may end up going that route. – harpo Jun 29 '12 at 16:39

1 Answers1

1

Your problem is not with cmd and how it handles quote characters. It is with start and how it handles quote characters. If the first parameter to start is a quoted string, it is the title of the command window, rather than the command to execute.

Usage looks like this

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
  [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
  [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
  [command/program] [parameters]

"title"     Title to display in window title bar.

You do this

cmd /c start "" "C:\Program Files"
John Watts
  • 8,717
  • 1
  • 31
  • 35
  • Yes! Thank you. I had "started" to suspect a problem with START itself, since it appeared that other commands could take such arguments. – harpo Jun 29 '12 at 16:45
  • It is definitely confusing. By the way, cmd /c will never require quotes because it always considers the rest of the command line to be the command. – John Watts Jun 29 '12 at 16:49
  • 1
    Quotes may not be required by CMD, but they are often used to make it easier to include redirection and pipes in the command to be executed. The special characters can be escaped instead, but I typically see the quotes. It definitely can get confusing. – dbenham Jun 29 '12 at 18:59