2017-08-31 335 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: ...前面實際上這裏沒有造成問題的原因。