2016-04-04 32 views
3

Benim için bazı işler yapmak için bir windows batch betiği yazmaya çalışıyorum. İşte kod:?Windows Batch: Zincirli İstemi ile ELSE

@echo off 

cls 

set /P AA="Is this information correct (Y/[N]) ? " 
if /I "%AA%" == "Y" (

    echo Setting up %DATE% %TIME% ... 

    echo Copying stuff to the places ... 

    set /P BB="Overwrite (Y/[N]) ? " 
    if /I "%BB%" == "Y" (

     echo Executing xxx ... 

    ) else echo NOPE1 [%BB%] 

    set /P CC="Overwrite (Y/[N]) ? " 
    if /I "%CC%" == "Y" (

     echo Executing xxx ... 

    ) else echo NOPE2 [%CC%] 

    echo All set ! 

) else echo Setup aborted [%AA%] ! 

pause 

2. ve 3. cevapları her zaman boş ve ben istemi gelen tırnak kaldırmak zaman `suçluyor' karakter. Kodun nesi yanlış?

Teşekkürler.

+2

[gecikmeli genişleme] (http://ss64.com/nt/delayedexpansion.html) – npocmaka

+2

kısa demo [gecikmeli genişletme] 'ye ihtiyacınız olacak (http://stackoverflow.com/a/30284028/2152082) – Stephan

+1

Teşekkür ederim. Ben yaptım. Doğru kodu göndereceğim! – Yore

cevap

3

Bu saçma türüdür, ancak her durumda nedeniyle 'Gecikmeli Genişletme' I kodu modifiye:

@echo off 
Setlocal EnableDelayedExpansion 

cls 

set /P AA="Is this information correct (Y/[N]) ? " 
if /I "%AA%" == "Y" (

    echo Setting up %DATE% %TIME% ... 

    echo Copying stuff to the places ... 

    set /P BB="Overwrite (Y/[N]) ? " 
    if /I "!BB!" == "Y" (

     echo Executing xxx ... 

    ) else echo NOPE1 [!BB!] 

    set /P CC="Overwrite (Y/[N]) ? " 
    if /I "!CC!" == "Y" (

     echo Executing xxx ... 

    ) else echo NOPE2 [!CC!] 

    echo All set ! 

) else echo Setup aborted [%AA%] ! 

pause 

Ve işe yarıyor! Teşekkürler npocmaka ve Stephan

İlgili konular