windows 7 bat 文件在用户键入响应后关闭

windows 7 bat file closes after user types response

我正在尝试编写一个 bat 文件,该文件在启动时会提示用户。我可以得到用户提示,但出现错误并且 bat 文件关闭。基本上,如果答案是 y,则调用 path 处的 vb,如果答案是 n,则 bat 退出。下面的语法是否接近?谢谢 :).

@ECHO OFF

:choice
set /P c=Do you want to send the DOSE report[y/n]?
if /I "%c%" EQU "Y" goto :L:\NGS\test_email_DOSE.xlsx
if /I "%c%" EQU "N" goto :exit
goto :choice
pause 
exit

试试这个:

@ECHO OFF
:choice
set /P c=Do you want to send the DOSE report[y/n]?
if /i %c%==y ( 
  L:\NGS\test_email_DOSE.xlsx
) else if /i not %c%==n goto choice
pause 

在此脚本中,只有当答案不是 'y' 时,才会达到第二个 if。此外,您使用的 goto 始终需要跳转到的标签。路径不是标签。

我当然假设 L:\NGS\test_email_DOSE.xlsx 是一个有效的路径。

当我在我的电脑上 运行 它产生以下内容(我将文件保存为 decide.cmd):

D:\tmp>decide
Do you want to send the DOSE report[y/n]?d
Do you want to send the DOSE report[y/n]?f
Do you want to send the DOSE report[y/n]?y  // (the Excel file is opened)  
Press any key to continue . . .

D:\tmp>

我可能会走这条路。以前的答案就可以了。但我认为这种方法看起来更干净。

@ECHO OFF
:choice
SET /P c=Do you want to send the DOSE report [Y/N]? 
IF /I %c%==Y (START "" "L:\NGS\test_email_DOSE.xlsx")
IF /I %c%==N GOTO :EOF
GOTO :choice