如何跳过系统消息"系统找不到指定的路径"在批处理脚本中

时间:2015-05-21 15:18:02

标签: windows batch-file

我编写了一个批处理文件,它将获得sql server命名实例(mssqlserver \ india)和磁盘可用空间。 文件内容如下所示:

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

现在我已经编写了一个批处理文件来生成基于文本文件Result.txt的html报告。但是我的批处理脚本正在选择mssqlserver \ India作为系统位置,并为文本文件中的每个条目弹出消息,在按下回车键后它将移动到下一个变量。

我想在没有任何用户交互的情况下忽略此消息。以下是我正在使用的脚本:

@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

1 个答案:

答案 0 :(得分: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