我用批处理语言制作了一个娱乐节目,但是有一个大错误:
@echo off
echo SimpleCmd is loading......
for /l %%i in (1,1,100000) do rem
cls
echo Loading end.
:ASKFORINPUT
set /p input=">>"
call :LoCase input
set input_bool=1
findstr /i /r /c:"^[ ]*:%input%\>" "%~f0" >nul 2>nul && goto %input%
::FUNCTION
:system
:system.menu
echo ---------MENU---------
echo ^| 1. System Command ^|
echo ^| 2. Back to Input ^|
if "%errorlevel%"=="1" (goto system.command)
if "%errorlevel%"=="2" (goto ASKFORINPUT)
:system.command
set /p systemcommand="cmd>>"
if %systemcommand%==simplecmd.back goto ASKFORINPUT
%systemcommand%
goto system.command
:random
:random.lowerlimit
set /p lowerlimit="Insert Lower Limit (1-32767) : "
if %lowerlimit% GTR 32767 (goto random.lowerlimit)
if %lowerlimit% LSS 1 (goto random.lowerlimit)
:random.upperlimit
set /p upperlimit="Insert Upper Limit (2-32768) : "
if %upperlimit% GTR 32768 (goto random.uppwerlimit)
if %upperlimit% LSS 2(goto random.upperlimt)
:random.generate
set /a number.random=%random%*%upperlimit%/32768+%lowerlimit%
goto ASKFORINPUT
::FUNCTION -END
::LOCASE
:LoCase
if %input_bool%==1 goto ASKFORINPUT
set input=%input:Q=q%
set input=%input:W=w%
set input=%input:E=e%
set input=%input:R=r%
set input=%input:T=t%
set input=%input:Y=y%
set input=%input:U=u%
set input=%input:I=i%
set input=%input:O=o%
set input=%input:P=p%
set input=%input:A=a%
set input=%input:S=s%
set input=%input:D=d%
set input=%input:F=f%
set input=%input:G=g%
set input=%input:H=h%
set input=%input:J=j%
set input=%input:K=k%
set input=%input:L=l%
set input=%input:Z=z%
set input=%input:X=x%
set input=%input:C=c%
set input=%input:V=v%
set input=%input:B=b%
set input=%input:N=n%
set input=%input:M=m%
set input_bool=0
::LOCASE -END 这是一个简单的程序,但bug是:
后藤在这个时候出乎意料
这条消息显示在我输入"system.command“并按enter之后。
我已经读了一遍又一遍,但根本看不出问题所在。
这一行有什么问题吗:findstr /i /r /c:"^[ ]*:%input%\>" "%~f0" >nul 2>nul && goto %input%?
任何帮助都将不胜感激。
发布于 2014-02-01 14:16:01
此时,input_bool将未定义,因此
if %input_bool%==1 goto ASKFORINPUT被解析为
if ==1 goto ASKFORINPUTIF语法是if string1运算符string2动作。
string1是==1,运算符是goto。goto不是if理解的运算符,所以它提出了反对意见。
你需要if "%possiblyemptyvariable%"=="1" goto ...
但是- GOTO在call编辑的例程中不是个好主意。如果必须的话,goto :eof退出例程,否则你的流控制就会失控.
发布于 2014-02-01 14:21:04
改变这个
if %input_bool%==1 goto ASKFORINPUT 到这个
echo if %input_bool%==1 goto ASKFORINPUT
pause你就会明白问题的所在。
https://stackoverflow.com/questions/21498604
复制相似问题