2017-08-31 108 views
1

这似乎很简单,但我很困难 - 一直在寻找大量近乎匹配的问题,但找不到答案。如何使用冒号回复消息?

所有我想做的事情是这样的:

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 

但是这没有效果。我怎样才能做到这一点?

UPDATE:

这行代码是在if块,这似乎有所作为!:

if exist "somefile" ( echo c:\another\test\file.h(22,11) : warning 123: this is a test warning )

+1

'echo c:\ another \ test \ file.h(22,11):warning 123:这是一个测试警告'对我来说完美无缺。所以我想,这只是你的代码片段,错误来自其他地方。请发布完整的代码。 – MichaelS

+3

我猜这行代码放在括号内的代码块中,所以'''被解释为关闭的那个,这使得':warning 123:...'是一个无效的命令;尝试通过'^)'逃脱''''... – aschipfl

+0

@aschipfl - 是的你是对的,它在'if(... here ...)'块内,我不知道会有对回声陈述的影响 - 没有徘徊它是如此困难。将它从if区块中移出并且工作正常:) ...随时添加该答案作为答案。我会更新我的问题 –

回答

4

我相信你的命令行放在内这样的代码块,例如:

if exist "c:\another\test\file.h" (
    echo c:\another\test\file.h(22,11) : warning 123: this is a test warning 
) 

因此,echo命令行中的关闭)被解释为整个块的关闭之一,而将: warning 123: this is a test warning作为无效的命令行。

为了解决这个问题,你需要通过一个插入符^,这是cmd的转义字符前面逃跑的)

if exist "c:\another\test\file.h" (
    echo c:\another\test\file.h(22,11^) : warning 123: this is a test warning 
) 

因此结肠:warning: ...前面实际上这里没有造成问题的原因。