【发布时间】:2022-12-07 09:26:02
【问题描述】:
我这里有 .bat 文件,我想弄清楚。我的大脑因为试图意识到这里出了什么问题而沸腾了!
这是我的代码:
echo off
setlocal
cls
:perm_ask
echo Make a permanent format?
CHOICE /C YN /N /T 15 /D N /M "Press Y for Yes and N for No: "
IF ERRORLEVEL 1 set perm=TRUE
IF ERRORLEVEL 2 set perm=FALSE
goto select_format
:select_format
cls
if "%perm%"=="TRUE" (echo You have selected the permanent save mode. Be CAREFUL! & echo.):: checking for truth
echo Select the file format:
echo =============
echo 1) .fb2 format
echo 2) .epub format
echo 3) .fb2 + .epub formats
CHOICE /C 123 /N /M "Format: "
IF ERRORLEVEL 1 set form=fb2
IF ERRORLEVEL 2 set form=epub
IF ERRORLEVEL 3 set form=fb2,epub
goto url_insert
:url_insert
cls
if "%perm%"=="TRUE" (echo TRUEEEE) else (echo FALSEEE):: checking for truth
if "%form%"=="fb2,epub" (echo You have chosen the .epub and .fb2 format
) else (echo You have chosen the .%form% format)
echo.
set /p url=Insert the URL:
Elib2Ebook.exe -u %url% -f %form%
if "%perm%"=="TRUE" (goto url_insert) else (goto ask_cont)
:ask_cont
echo.
set ERRORLEVEL=0:: trying to reset a huge negative value
CHOICE /C YN /M "Continue? "
IF ERRORLEVEL 1 goto select_format
IF ERRORLEVEL 2 goto exit
:exit
@exit
在perm_ask问是否设置永久文件格式。
在select_form中我给form赋值
在url_insert中插入链接,程序执行完毕
在ask_count中,如果我在perm_ask中回答否,则要求继续或退出...
毕竟,如果我不更改顺序,即使我在Continue? 答案是否定的,它仍然会转到select_form
所以问题是。如果我之前用 ERRORLEVEL 把所有东西都按顺序排列,我什至不需要以相反的顺序排列它(因为它出于某种原因不起作用!)。然后在 url_insert 我对 Continue? 有疑问,如果不更改顺序或不更改顺序:
IF %ERRORLEVEL% == "1" goto select_format
IF %ERRORLEVEL% == "2" goto exit
那么问题来了……为什么?为什么在那之前一切都很好,但之后您要么需要更改顺序,要么将 ERRORLEVEL 分配给变量?我尝试在其他地方(perm_ask 和select_form)更改 ERRORLEVEL 的顺序,但它只是破坏了一切!
【问题讨论】:
标签: windows batch-file cmd command-prompt logical-operators