2015-05-21 53 views
0

我寫了一個批處理文件,它將獲得sql server命名實例(mssqlserver \ india)和磁盤可用空間。 對文件內容如下:如何在批處理腳本中跳過系統消息「系統找不到指定的路徑」

mssqlserver\India,D,20 
mssqlserver\India,C,30 

現在我已經寫一個批處理文件來生成基於文本文件Result.txt一個HTML報告。但是,我的批處理腳本正在將mssqlserver \ India選爲系統位置,並在文本文件中爲每個條目彈出消息,並在按Enter鍵後移至下一個變量。

我想在沒有任何用戶交互的情況下忽略此消息。下面是我使用的腳本:

@ECHO off 
setlocal EnableDelayedExpansion 
SETLOCAL 
cd C:\Users 
goto head >nul 

:head 
FOR /F "tokens=1-6 delims=," %%G IN (Result.txt) DO (
%%G%%H%%I 
set temphost1=%%G 
set temphost2=%%H 
set temphost3=%%I 
call :stripquotes %temphost1% %temphost2% %temphost3% >NUL 
) 
goto :end 
:stripquotes 
echo ^<tr bgcolor="#90EE90"^>^<td^>^%temphost1%^</td^>^<td^>^%temphost2%^</td^>^<td^>^%temphost3%^</td^>^</tr^>^ >> C:\Users\Report.html 
:END 
CLS 
ECHO COMPLETED 
PAUSE 

回答

0

隨着一些@rem評論的變化,下一個腳本可以工作:

@ECHO off 
@rem EnableDelayedExpansion not applied in the code 
@rem use enableextensions in the next line 
setlocal EnableDelayedExpansion 
@rem superabundant SETLOCAL 
cd C:\Users 
@rem Why "goto head >nul" as GOTO does not produce any output? 
@rem And why next "goto head" at all? 
goto head >nul 

:head 
FOR /F "tokens=1-6 delims=," %%G IN (Result.txt) DO (
    @rem this caused the error message %%G%%H%%I 
    set temphost1=%%G 
    set temphost2=%%H 
    set temphost3=%%I 
    call :stripquotes 
    @rem this were superabundant and harmful %temphost1% %temphost2% %temphost3% >NUL 
) 
goto :end 

:stripquotes 
@rem some superfluous `^` carets removed from next line but the last one was harmful 
echo ^<tr bgcolor="#90EE90"^>^<td^>%temphost1%^</td^>^<td^>%temphost2%^</td^>^<td^>%temphost3%^</td^>^</tr^> >> C:\Users\Report.html 
@rem next line to return from the :stripquotes subroutine 
goto :eof 

:END 
CLS 
ECHO COMPLETED 
PAUSE 
相關問題