繁体   English   中英

无法将 icacls 运行到有空格的目录

[英]Can't run icacls to a directory with spaces

我正在尝试在我的计算机上的目录中运行一个简单的 icacls,但我遇到了这个错误:


PS C:\Users\gguer\Documents> icacls.exe '.\My Digital Editions\'
.\My Digital Editions": The filename, directory name, or volume label syntax is incorrect.
Successfully processed 0 files; Failed processing 1 files

正如我所想的那样,我使用单引号来转义空格,所以我不知道这里有什么问题。 希望您能够帮助我。 谢谢!

解决了。 只需要删除最后一个反斜杠。 干杯。

要为您自己的有效解决方法添加解释(在您的论点中不包括尾随\ ):

您所看到的是Windows PowerShell中关于如何将 arguments 传递给外部程序的错误 - 此问题已Z3D265B4E1EEB10DCCDF1 (7)88810DCCDF1 (核心)

在幕后, PowerShell(必须)将包含空格的引号参数转换为引号形式,因为只能假定外部 CLI 理解"..."引用。

大多数 CLI 使用的命令行解析规则将序列\"视为转义"字符,即,将"字符视为参数的逐字部分而不是对其进行定界。

因此,双引号字符串末尾的逐字\本身必须转义为\\才能被识别 -这就是 Windows PowerShell 忽略做的事情

也就是说,Windows PowerShell 将您的调用翻译如下:

# Resulting command line as used behind the scenes for actual invocation.
# WinPS: BROKEN, because the \ at the end isn't escaped.
icacls.exe ".\My Digital Editions\"

icacls.exe解析此命令行时,它会逐字查看.\My Digital Editions" (注意末尾的逐字" ),这反映在错误消息中。

相比之下,PowerShell(核心)确实执行了必要的 escaping:

# Resulting command line as used behind the scenes for actual invocation.
# PowerShell (Core): OK
icacls.exe ".\My Digital Editions\\"

作为旁白:

自 7.2.x 起,PowerShell(核心)中仍然存在一个影响"嵌入在 arguments 中如何传递给外部程序”的相关错误- 请参阅此答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM