- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我遇到了一个批处理文件问题 (Windows 7 x64)。我设法将其缩减为以下内容(有两个空注释行;是否有实际注释似乎并不重要):
@echo off
if /i [%1]==[] (
echo A
::
::
echo B
)
将其放入批处理文件中,然后不带参数运行它会产生以下输出:
A
The system cannot find the drive specified.
B
删除其中一个 ::
行,或删除周围的 if
,修复 问题,以便获得预期的输出:
A
B
这是怎么回事?为什么要寻找驱动器?
编辑
感谢您的回复。所以我的问题归结为:
What are the rules for determining whether
::
means "start of comment" or "drive letter colon"?
也许切换回 REM
来添加注释会更容易,这样就不会出现歧义,但我确实发现 ::
样式更易于阅读。
最佳答案
这是批处理代码块中的一个模糊效果。
在一个代码块中,一行中的一个标签总是需要一个语法规则完全不同的次要行(对于 次要 行)。
SO: goto command not working
第二行必须是命令或简单标签,但不能是括号、双冒号或附加有括号的内部命令。
MC ND 解释说 :
在这里像普通的盘符一样使用,这是真的!
但只有在次要行中,甚至你可以通过 subst::C:\
来抑制错误,该行被处理为标签(你不能启动任何东西)。
subst :: C:\
(
:label
::\windows\system32\calc.exe
)
即使该行是标签,辅助行也接受 &
。
失败样本
(
:Label at the end fails
)
(
:label
(
echo new Block fails
)
echo ...
)
(
:label
:: Double colon fails
)
(
:label
echo( fails also, as now a file named "echo(" is searched for execution
)
现在正在工作
(
::Works
:with a "normal" label in the second line
)
(
:But this label! & echo This will not echo'd
:but & echo You can see this !
)
(
:label
echo or a simple command works too
)
有时 ::
被用作 comment style ,如果您不关心辅助线,这可能会导致 block 内部出现问题。
编辑:回答你的第二个问题
What are the rules for determining whether :: means "start of comment" or "drive letter colon"?
第一个 ::
始终是注释或标签,在下一行中它始终是 驱动器号冒号
。
关于windows - 批处理文件中出现意外的 "The system cannot find the drive specified.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19843849/
我是一名优秀的程序员,十分优秀!