2017-05-03 65 views
0

這裏是我的代碼Windows批處理:如果條件未通過驗證

ECHO off 
CLS 
ECHO List of VMs: 
ECHO ............. 
cd /D "F:\VMs" 
setlocal enabledelayedexpansion 
set num=0 
for /f "tokens=*" %%i in ('dir /s/b *.vmx') do set /a num+=1&set VM[!num!]=%%i 
set numberOfVMs=0 
for /F "tokens=2 delims==" %%s in ('set VM[') do (
    set /a numberOfVMs+=1 
    echo !numberOfVMs! -^> %%s 
) 
ECHO. 
ECHO List of Running VMs: 
ECHO ..................... 
set num=-1 
for /f "tokens=*" %%i in ('vmrun -T ws list') do (
    set /a num+=1 
    if !num! NEQ 0 set RUNNINGVM[!num!]=%%i 
) 
set numberOfRunningVMs=0 
for /F "tokens=2 delims==" %%s in ('set RUNNINGVM[') do (
    set /a numberOfRunningVMs+=1 
    echo !numberOfRunningVMs! -^> %%s 
) 
ECHO. 
ECHO List of Available VMs: 
ECHO ....................... 
for /l %%x in (1, 1, %numberOfVMs%) do ( 
    ::echo !VM[%%x]! 
    for /l %%y in (1, 1, %numberOfRunningVMs%) do (
      echo !VM[%%x]! 
      echo !RUNNINGVM[%%y]! 
     if "!VM[%%x]!"=="!RUNNINGVM[%%y]!" (
      echo "success" 
     ) 
    ) 
) 

陣列varibale 'VM' 低於值:

F:\虛擬機\ PD-UI-測試,Win10- x64的Office2016-32bit.vmwarevm \ Windows的10 x64.vmx

F:\虛擬機\ PD-UI-測試-Win10-x64的Office2016-64bit.vmwarevm \ Windows的10 x64.vmx

F:\ VMs \ PD-UI-Tests-Win7-x64-Offic e2013-32bit.vmwarevm \ Windows7的-x64的RTM.vmx

陣列varibale 'RUNNINGVM' 具有下面的值:

F:\虛擬機\ PD-UI-試驗 - Win7的-x64的Office2013-32bit .vmwarevm \ Windows7-x64-RTM.vmx

但是,儘管VM [3]等於RUNNINGVM [1],但最終的if條件永遠不會變爲「真」。我錯過了什麼?請幫助

+0

輸出是什麼?如果您在「可用虛擬機列表:」之後立即打開回顯,是否顯示任何有趣的內容? – jdigital

回答

0

請勿在代碼塊中使用::樣式的註釋,因爲它實際上是一個破碎的標籤,並且標籤會打破代碼塊。改爲使用rem