我是一个新手,需要帮助,如何在用户输入任何非法字符时停止关闭此批处理文件...
例如,当用户输入为“;”时或“&&”,并且输入基本上使批处理文件崩溃。
我的代码:
@echo off
cls
:start
taskkill /f /im process1.exe
taskkill /f /im process2.exe
taskkill /f /im process3.exe
taskkill /f /im process4.exe
taskkill /f /im process5.exe
:restart
set choice=
set /p choice="Do you want to run these batch commands again? Type 'y' and press 'Enter' to re-execute the batch commands again or type 'n' and press 'Enter' to terminate: "
if not '%choice%'=='n' if not '%choice%'=='y' goto restart
if '%choice%'=='n' set choice=%choice:~0,1%
if '%choice%'=='y' goto start
:end
谢谢!
最佳答案
输入任何非法字符后,如何停止关闭该批处理文件?
选项1 :
使用if
而不是反引号来编写"
表达式:
if not "%choice%"=="n" if not "%choice%"=="y" goto restart
if "%choice%"=="n" set choice=%choice:~0,1%
if "%choice%"=="y" goto start
选项2(更好):
使用
choice
:choice /c yn /m "Do you want to run these batch commands again? Press [y] or [n]
if errorlevel 2 goto :exit
if errorlevel 1 goto :restart
进一步阅读
关于batch-file - 我需要帮助,当用户输入非法字符时如何停止关闭此批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42987572/