我正在尝试执行这样的命令:
CMD /C "C:\Users\Richard(R)D\abc.bat"
我收到错误消息:
'C:\Users\Richard' is not recognized as an internal or external command
如何执行驻留在使用圆括号的文件夹中的命令?
答案 0 :(得分:4)
为什么?
如果您阅读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.
这意味着
cmd /c "C:\Users\Richard(R)D\abc.bat"
删除引号和剩余命令
cmd /c C:\Users\Richard(R)D\abc.bat
括号有问题。
如何?的
对于此精确命令,您可以转义括号
cmd /c "C:\Users\Richard^(R^)D\abc.bat"
或者对于一般解决方案,您可以包含文件的引号
cmd /c ""C:\Users\Richard(R)D\abc.bat""
并且更好(如果从命令行执行)也会转义第一个引号以避免引用区域中的解析器问题启动/停止(在这种情况下不需要)
cmd /c ^""C:\Users\Richard(R)D\abc.bat""
答案 1 :(得分:3)
尝试使用抑扬符^
转义括号CMD /C "C:\Users\Richard^(R^)D\abc.bat"
答案 2 :(得分:-1)
你错过了结尾引号,所以命令就像这样
CMD /C "C:\Users\Richard(R)D\abc.bat"
希望这有助于你解决它。