批处理文件终止问题

时间:2014-02-13 13:19:04

标签: batch-file

我的批处理程序出现问题显然没有理由退出。我发现如果你使用0它可以正常工作,但是1退出,2运行1 ???看到0和1几乎完全相互复制是没有意义的。任何帮助,将不胜感激。作为旁注,我确实有select.exe和dev工具来使用cecopy。

这是我的代码:

@echo off
title MK2XXX Depot test
rem Automation for MK2xxx app/plat copying
rem v 0.01

:main
echo MK2xxx App/Plat copyBot
echo v 0.01
echo.
echo Please select your unit:
echo 0 MK2046
echo 1 MK2250
echo 2 Exit
:: prompt user for which unit they wish to copy files to

choice /c:012 /n
        if %errorlevel% == 0 goto MK2046 
        if %errorlevel% == 1 goto MK2250 
        if %errorlevel% == 2 goto end   


:MK2046
cls

echo Make sure you have allowed pcConnection on unit
echo Connect RS 485 cable, press enter once Sync is complete
    :: wait until unit is synced properly
pause
cls
cecopy C:\"FILEPATH dev:\Application\
cecopy C:\"FILEPATH dev:\Application\
cecopy C:\"FILEPATH dev:\Application\
cecopy C:\"FILEPATH
cecopy C:\"FILEPATH
pause
goto main




:MK2250
cls
pause
echo Make sure you have allowed pcConnection on unit
echo Connect RS 485 cable, press enter once Sync is complete
    :: wait until unit is synced properly
pause
cls
cecopy C:\"FILEPATH
cecopy C:\"FILEPATH
cecopy C:\"FILEPATH dev:\Application\
cecopy C:\"FILEPATH
cecopy C:\"FILEPATH
pause
goto main

:end

2 个答案:

答案 0 :(得分:0)

好的问题是,如果你使用它可能是不可预测的,这是一个你应该使用的更稳定的。因为可能存在其他可能影响错误级别的事情。

set /p result=Choice:
if %result%==0 goto MK2046
if %result%==1 goto MK2250
if %result%==2 goto end

所以你的代码应该是这样的:

@echo off
title MK2XXX Depot test
rem Automation for MK2xxx app/plat copying
rem v 0.01

:main
echo MK2xxx App/Plat copyBot
echo v 0.01
echo.
echo Please select your unit:
echo 0 MK2046
echo 1 MK2250
echo 2 Exit
:: prompt user for which unit they wish to copy files to

set /p result=Choice:
if %result%==0 goto MK2046
if %result%==1 goto MK2250
if %result%==2 goto end 


:MK2046
cls

echo Make sure you have allowed pcConnection on unit
echo Connect RS 485 cable, press enter once Sync is complete
    :: wait until unit is synced properly
pause
cls
cecopy C:\"Flash 2"\MK2046-xxxxxxxx\"Depot Test"\App\*.reg dev:\Application\
cecopy C:\"Flash 2"\MK2046-xxxxxxxx\"Depot Test"\App\*.key dev:\Application\
cecopy C:\"Flash 2"\MK2046-xxxxxxxx\"Depot Test"\App\radio.def dev:\Application\
cecopy C:\"Flash 2"\MK2046-xxxxxxxx\"Depot Test"\Plat\*.reg dev:\Platform\
cecopy C:\"Flash 2"\MK2046-xxxxxxxx\"Depot Test"\Plat\*.cpy dev:\Platform\
pause
goto main




:MK2250
cls
pause
echo Make sure you have allowed pcConnection on unit
echo Connect RS 485 cable, press enter once Sync is complete
    :: wait until unit is synced properly
pause
cls
cecopy C:\"Flash 2"\MK2250-xxxxxxxx\"Depot Test"\App\*.reg dev:\Application\
cecopy C:\"Flash 2"\MK2250-xxxxxxxx\"Depot Test"\App\*.key dev:\Application\
cecopy C:\"Flash 2"\MK2250-xxxxxxxx\"Depot Test"\App\radio.def dev:\Application\
cecopy C:\"Flash 2"\MK2250-xxxxxxxx\"Depot Test"\Plat\*.reg dev:\Platform\
cecopy C:\"Flash 2"\MK2250-xxxxxxxx\"Depot Test"\Plat\*.cpy dev:\Platform\
pause
goto main

:end

放手一搏。

答案 1 :(得分:0)

choice为第一个选择(%errorlevel%)提供0 1,而不是0.所以您的代码应如下所示:

choice /c:012 /n
        if %errorlevel% == 1 goto MK2046 
        if %errorlevel% == 2 goto MK2250 
        if %errorlevel% == 3 goto end   
使用字母而不是数字时,可能不那么容易混淆:choice /c:abc输入a的{​​{1}}为1(第一个字母)