2013-03-29 218 views
0

在DOS Windows批處理文件「在這個時候意外」,我收到以下錯誤:批處理文件錯誤,

45.0.31322.0 unexpected at this time. 

的數字45.0.31322.0AgtVersion變量的內容。

下面是代碼:

if agentVersion: 45.0.31322.0==agentVersion: 45.0.31322.0 set AgtVersion=45.0.31322.0 

:: Identify HPSA Agent Version 
for /f "delims=" %%x in ('get_info.bat ^| find /i "agentVersion: 4"') do @set hpsaAGT=%%x 

:: Checks agent version and store in new variable 
if %hpsaAGT%==agentVersion: 45.0.31322.0 set AgtVersion=45.0.31322.0 

:: THE ERROR HAPPENS HERE: 
:: the above line throws a: "45.0.31322.0 unexpected at this time." 

if %hpsaAGT%==agentVersion: 40.0.0.1.106 set AgtVersion=40.0.0.1.106 
if agentVersion: 45.0.31322.0==agentVersion: 45.0.31322.0 set AgtVersion=45.0.31322.0 

:: Display HPSA Agent Version and store in txt file 
echo %AgtVersion%> c:\temp\hpsa_agent\hpsaAGT.txt 
echo Current HPSA Core : %AgtVersion% 

這個錯誤是什麼消息呢?

+1

使用雙引號,如果你的字符串包含空格:如果 「%hpsaAGT%」 == 「agentVersion:45.0.31322.0」 設置AgtVersion = 45.0.31322.0 – Stephan

+0

可能[%x的重複在這個時候是意想不到的。批處理腳本](http://stackoverflow.com/questions/2190295/x-was-unexpected-at-this-time-batch-script) –

回答

2

您正將一個變量與一個帶有空格的未加引號的字符串進行比較。 DOS將agentVersion:45.0.31322.0解釋爲兩個不同的標記。第二個令牌是意外的。

if %hpsaAGT%==agentVersion: 45.0.31322.0 

應該是:

if "%hpsaAGT%"=="agentVersion: 45.0.31322.0"