为什么cmd会抛出C:\ Program甚至在路径周围都有引号?

时间:2016-10-13 18:59:29

标签: windows cmd

我做的是:

在Windows上

,按“Windows”按钮,弹出开始菜单。我开始打字:

"C:\Windows\System32\cmd.exe" /k "C:\Program Files (x86)\my\my.exe" -c "C:\Program Files (x86)\my\data.conf" -cert "C:\Program Files (x86)\my\my.key"

但是当cmd提示出现时,它会显示:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

不确定为什么这会给我错误,因为我已经在路径周围引用了。这可能只是一些愚蠢的事情,但非常感谢第二双眼睛!

2 个答案:

答案 0 :(得分:2)

使用cmd /?

中的以下说明
  
      
  1. 否则,旧行为是查看第一个字符是否为引号字符,如果是,则删除前导字符并删除最后一个字符   在命令行上引用字符,保留后面的任何文本   最后引用字符。
  2.   

您的行应更正为:

"C:\Windows\System32\cmd.exe" /k ""C:\Program Files (x86)\my\my.exe" -c "C:\Program Files (x86)\my\data.conf" -cert "C:\Program Files (x86)\my\my.key""

(基本上是"cmd.exe" /k "command using "quoted parts""(在引用的表达式中引用了字符串)

注意:您也可以(应该)使用"C:\Windows\System32\cmd.exe"

代替"%comspec%"

答案 1 :(得分:1)

当一行只有两个时,双引号字符只能由cmd正确处理。删除所有内容,包括" / k"从你输入的内容和运行结果 - 它在类似的情况下对我有用。请注意,您可以将键入的内容保存到.bat文件中,然后运行该文件以保存重复键入(或重复粘贴)。

证据可以在http://www.computerhope.com/cmd.htm找到,或者如果你运行:

cmd /?

您将看到以下内容:

If /C or /K is specified, then the remainder of the command line after the
switch is processed as a command line, where the following logic is used to
process quote (") characters:

1. If all of the following conditions are met, then quote characters on 
the command line are preserved:    
 - no /S switch
 - exactly two quote characters
 - no special characters between the two quote characters, where special is
   one of: &<>()@^|
 - there are one or more whitespace characters between the two quote
   characters
 - the string between the two quote characters is the name of an executable
   file.

2. Otherwise, old behavior is to see if the first character is a quote
character and if so, strip the leading character and remove the last quote
character on the command line, preserving any text after the last quote
character.