是不是不能"pass a quoted string as an argument to a command that needs to be quoted itself"?



我知道,我知道。 这样疯狂就谎了。

标题指的是这个伟大的答案。 我只想一劳永逸地解决是否真的可以做这样的事情:

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.

我只想启动名称中可能包含空格的文件夹或 URL。 这是"先进"吗?

我已经看到了这个问题,但"在上面不起作用。

我从 VFP 中的 WScript.Shell 对象调用它,因此我必须将整个命令作为单个字符串传递。 但我想解决一个更普遍的问题以供参考。

您的问题不在于cmd以及它如何处理引号字符。它与开始以及它如何处理引号字符。如果要启动的第一个参数是带引号的字符串,则它是命令窗口的标题,而不是要执行的命令。

用法如下所示

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.

你这样做

cmd /c start "" "C:Program Files"

最新更新