windows - 如何回显其中带有冒号的消息?

标签 windows batch-file

这看起来很简单,但我被困住了 - 一直在搜索许多几乎匹配的问题,但就是找不到答案。

我想做的就是这样:

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/

相关文章:

windows - 连接 ECONNREFUSED 127.0.0.1 :27017 Mongo in Docker + WSL version 2

c++ - 外部限制程序帧率

command-line - 制作用户名和密码的命令提示符

Windows 批处理变量

windows - Visual Studio 或 Eclipse - 哪个更适合 Windows 上的 Qt?

windows - 如何在没有 Ping 统计信息的情况下获取 ping 命令的输出?

batch-file - 如何使用批处理脚本获取呈现特定文件夹的批处理脚本位置(以编程方式)

batch-file - Windows 2000 说超时不是命令或批处理文件

windows - 如何获取powerscript版本并在批处理脚本中升级?

batch-file - 使用命令提示符复制文件夹并重命名