这看起来很简单,但我被困住了 - 一直在搜索许多几乎匹配的问题,但就是找不到答案。
我想做的就是这样:
echo c:\another\test\file.h(22,11) : warning 123: this is a test warning
但这给出了错误:: was unexpected at this time
。
所以我尝试了:
echo "c:\another\test\file.h(22,11) : warning 123: this is a test warning"
产生:"c:\another\test\file.h(22,11) : warning 123: this is a test warning"
。但我不想要引号。所以我尝试使用转义符“^”:
echo c^:\another\test\file.h(22,11) ^: warning 123^: this is a test warning
但这没有任何效果。我怎样才能做到这一点?
更新:
这行代码在 if block 中,这似乎有所不同!:
如果存在“somefile”(
echo c:\another\test\file.h(22,11) : 警告 123: 这是一个测试警告
)
最佳答案
我相信您的命令行放在一个带括号的代码块中,例如:
if exist "c:\another\test\file.h" (
echo c:\another\test\file.h(22,11) : warning 123: this is a test warning
)
因此 echo
命令行中的结束 )
被解释为整个 block 的结束之一,留下部分 : warning 123: this is a将警告
测试为无效的命令行。
要解决这个问题,您需要在 )
前面加上一个脱字符 ^
来转义它,这是 cmd
的转义字符:
if exist "c:\another\test\file.h" (
echo c:\another\test\file.h(22,11^) : warning 123: this is a test warning
)
因此 warning: ...
前面的冒号 :
实际上不会导致这里的问题。
关于windows - 如何回显其中带有冒号的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45983858/