Batch file 如果在批处理中运行命令时出现任何错误,请停止

Batch file 如果在批处理中运行命令时出现任何错误,请停止,batch-file,reset,errorlevel,Batch File,Reset,Errorlevel,我刚刚制作了这个批量文件,它完全重置了我的手机!但我只是想知道,如果任何命令不能成功运行,我是否可以阻止它运行。如果它仍然是RUUNING命令,它可能会硬砖块我的手机,我们都不希望它发生。那么,我该如何阻止它呢 ECHO Brought to you by Rocker223 @XDA ECHO -__-__-__-__-__-__-__-__-__-__- ECHO. Echo Motorolla MOTO G3(2015) ECHO Reset tool ECHO

我刚刚制作了这个批量文件,它完全重置了我的手机!但我只是想知道,如果任何命令不能成功运行,我是否可以阻止它运行。如果它仍然是RUUNING命令,它可能会硬砖块我的手机,我们都不希望它发生。那么,我该如何阻止它呢

ECHO Brought to you by Rocker223 @XDA
ECHO -__-__-__-__-__-__-__-__-__-__-
ECHO.
Echo     Motorolla MOTO G3(2015)
ECHO           Reset tool
ECHO -__-__-__-__-__-__-__-__-__-__-
cd /d %CD%
title Reset your mobile!
set p=0
ECHO ---Making sure your phone is in fastboot mode---
ECHO Press c to Cancel!
choice /c ync /M "Is your phone in fastboot mode"
if %errorlevel% == 2 ECHO Rebooting
if %errorlevel% == 2 adb reboot bootloader
if %errorlevel% == 3 exit(0)
title Flashing Partition file! Step:1 of 20
ECHO Flashing Partition file!
fastboot flash partition gpt.bin
title Flashing bootloader! 
ECHO Flashing bootloader!
fastboot flash bootloader bootloader.img
title Flashing Logo! Step:2 of 20
ECHO Flashing Logo!
fastboot flash logo logo.bin
title Flashing boot file! Step:3 of 20
ECHO Flashing boot file!
fastboot flash boot boot.img
title Flashing Recovery! Step:4 of 20
ECHO Flashing Recovery!
fastboot flash recovery recovery.img
set /a n=5
Title flashinng system image Step:%n% of 20
ECHO Flashing system image files might take a minute or two....
fastboot flash system system.img_sparsechunk.0
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.1
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.2
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.3
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.4
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.5
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.6
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.7
set /a n=n+1
Title Finalising... Step:%n% of 20
ECHO Finalising...
fastboot flash modem NON-HLOS.bin
set /a n=n+1
Title Finalising... Step:%n% of 20
fastboot erase modemst1
set /a n=n+1
Title Finalising... Step:%n% of 20
fastboot erase modemst2
set /a n=n+1
Title Finalising... Step:%n% of 20
fastboot flash fsg fsg.mbn
set /a n=n+1
title Erasing Data... Step:%n% of 20
ECHO Erasing Data...
fastboot erase cache
set /a n=n+1
title Erasing Data... Step:%n% of 20
fastboot erase userdata
set /a n=n+1
title Rebooting your phone! Step:%n% of 20
ECHO Rebooting your phone!
fastboot reboot
title Finished!
ECHO All Done! Phone has been reset successfully!

您必须在批处理中的每个命令后检查errorlevel

查看请阅读:顺便说一下:
exit(0)
非常有趣。您使用命令行编写了批处理脚本,而不是使用函数编写的程序。在命令提示窗口中运行
exit/?
,以获取有关此命令的帮助和正确用法。我建议使用
exit/b0
。怎么做??