我有一個批處理文件,它接收包含我要報告給TeamCity的多行註釋(堆棧跟蹤)的輸入參數。下面的代碼適用於單行註釋,並從消息中刪除括號和引號。問題是隻有第一行多行消息被報告。在批處理文件中向TeamCity報告多行註釋
rem Try to remove line breaks (not working)
setlocal EnableDelayedExpansion
SET message=%~1
set ^"message=!message:^
= !"
rem Remove square brackets and quotes
SET message=%message:[=%
SET message=%message:]=%
SET message=%message:'=%
rem Print message to console for TeamCity
echo ##teamcity[progressMessage '%message%']
有沒有辦法在echo語句之前刪除所有換行符並將它們替換爲空格?
仍然需要刪除命令行invokation測試它(我得到的東西像'##的TeamCity [progressMessage「CMD \ C測試一個\ ntwo \ rthree ']',但這真的很酷!很高興我不必使用它,但:-) +1從我這裏! – marapet
@marapet你說得對,但是這需要一些關於調用名稱的知識。因爲它可以通過'cmd/c test.bat one-two-three'調用,但它也可以是'cmd/c test one-two-three'或者甚至是'cmd/c'/ path/space/test「一個 - 兩個-three'。所以去除頭部並不容易。 – jeb