2015-10-17 21 views
0

我試圖編寫一個bat文件,啓動後會提示用戶。我可以得到用戶提示,但會出現錯誤,並關閉文件bat。基本上,如果答案是y,那麼在path處調用vb,如果答案是n,則退出bat。下面的語法關閉了嗎?謝謝 :)。Windows 7 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 
+0

刪除'@echo off'進行調試! – aschipfl

+0

我做了並且'bat'文件關閉以快速讀取錯誤。謝謝 :)。 – Chris

+0

這就是'暫停'用於... ;-) – aschipfl

回答

1

試試這個:

@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 

在這個腳本第二if時,得到的答覆是沒有 'Y' 只達到。此外,您使用的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> 
+0

使用我得到的提示,但'bat'很快關閉。謝謝 :)。 – Chris

+0

腳本是否至少要求您輸入一個輸入? – cars10m

+0

我得到用戶提示並鍵入「y」,然後關閉。非常感謝你 :)。 – Chris

0

我可能會走這條路。以前的答案會很好。但是我認爲這種方法看起來更清潔。

@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 
相關問題