这个批处理脚本有什么问题吗?
@echo off
:a
title DISCORD.PY BOT RUNNER
cls
color 0a
python bot.py
if errorlevel == 1 (
color 4
echo.
echo ERROR
echo.
echo [1] CLOSE : [2] RESTART
set /p error = ""
if %error% == 1 exit
if %error% == 2 goto a
)
echo BOT IS CLOSED
echo.
echo [1] CLOSE
set /p closed = ""
if %closed% == 1 exit
谁能告诉我这个脚本有什么问题吗? 我看没有什么问题。 BC 我想制作一个discord.py 机器人启动器。
@echo off
:a
title DISCORD.PY BOT RUNNER
cls
color 0a
python bot.py
if errorlevel == 1 (
color 4
echo.
echo ERROR
echo.
echo [1] CLOSE : [2] RESTART
set /p error = ""
if %error% == 1 exit
if %error% == 2 goto a
)
echo BOT IS CLOSED
echo.
echo [1] CLOSE
set /p closed = ""
if %closed% == 1 exit
Can anyone say me whats wrong with this script?
I see there are nothing wrong.
Bc i want to make an discord.py bot starter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
errorlevel == 1
- 字符串errorlevel
永远不会与字符串1
相同。您需要errorlevel
的值,即%errorlevel%
。由于您在括号内的语句序列(即
块
)内设置error
的值,因此批处理将评估整个 语句从if
到右括号,并用解析语句时该变量的值替换每个%variable%
,即在执行之前。您正在更改块内的error
值,因此您需要提取其运行时值进行测试,因此需要调用delayedexpansion
。请参阅 https://stackoverflow.com/a/30284028/2128947另:
set /p 变量 =< /code> 将建立一个名为variableSpace 的变量,而不是variable。
=
之前的空格 很重要。errorlevel == 1
- the stringerrorlevel
will never be the same as the string1
. You need the value oferrorlevel
, that is%errorlevel%
.Since you are setting the value of
error
within a parenthesised sequence of statements (ie. ablock
) then batch will evaluate the entire statement from theif
to the closing parenthesis, and substitute for each%variable%
with the valu of that variable at the time the statement was parsed, that is, before it is executed. You are changing the value oferror
within the block, so you need to extract its run-time value for testing and thus you need to invokedelayedexpansion
. Please see https://stackoverflow.com/a/30284028/2128947ALSO :
set /p variable =
will establish a variable named variableSpace not variable. The space before the=
is significant.