我是Lloyd,我是Stack Overflow的新手。
无论如何,我正在写一个关于计算器的批处理文件。但是,有一件事我注意到,即使没有错误,错误级别也始终设置为1。
我也试过这个我在谷歌搜索过的命令:
set errorlev=0
但是,那个命令什么都不做;我的意思是,它仍然设置为errorlevel 1。
所以,这是我的批处理文件:
@echo off
cls
title Calculator
ping 1.1.1.1 -n 1 -w 1000 > nul
echo.
echo Welcome to Calculator!
ping 1.1.1.1 -n 1 -w 1000 > nul
echo.
echo Initializing ...
ping 1.1.1.1 -n 1 -w 500 > nul
echo Please wait ...
ping 1.1.1.1 -n 1 -w 3000 > nul
goto Input
:Input
cls
color 07
echo Please choose an operation.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /p "op=>"
if %op%==Addition goto Addition
if %op%==addition goto Addition
if %op%==Subtraction goto Subtraction
if %op%==subtraction goto Subtraction
if %op%==Multiplication goto Multiplication
if %op%==multiplication goto Multiplication
if %op%==Division goto Division
if %op%==division goto Division
cls
ping 1.1.1.1 -n 1 -w 500 > nul
color 0c
echo ERROR : That's not a valid operation.
echo.
ping 1.1.1.1 -n 1 -w 500 > nul
echo You have entered "%op%".
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Input
:Addition
cls
title Calculator - Addition
echo Addition:
echo.
echo _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the first addend.
ping 1.1.1.1 -n 1 -w 500 > nul
set /p "add1=>"
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Addition1
:Addition1
cls
title Calculator - Addition
echo Addition:
echo.
echo %add1% + _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the second addend.
ping 1.1.1.1 -n 1 -w 500 > nul
set /p "add2=>"
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Addition2
:Addition2
cls
title Calculator - Addition
echo Addition:
echo.
echo %add1% + %add2% = ?
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /a "resultadd = %add1% + %add2%"
echo The answer is %resultadd%.
rem %resultadd%
ping 1.1.1.1 -n 1 -w 2000 > nul
echo.
echo Type "Back" to enter another problem.
echo Type "Exit" to exit the Calculator.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /p "adda=>"
if %adda%=="Back" goto Input
if %adda%=="back" goto Input
if %adda%==Back goto Input
if %adda%==back goto Input
if %adda%=="Exit" goto Exit
if %adda%=="exit" goto Exit
if %adda%==Exit goto Exit
if %adda%==exit goto Exit
:Subtraction
cls
title Calculator - Subtraction
echo Subtraction:
echo.
echo _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the minuend.
ping 1.1.1.1 -n 1 -w 500 > nul
set /p "subtract1=>"
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Subtraction1
:Subtraction1
cls
title Calculator - Subtraction
echo Subtraction:
echo.
echo %subtract1% - _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the subtrahend.
ping 1.1.1.1 -n 1 -w 500 > nul
set /p "subtract2=>"
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Subtraction2
:Subtraction2
cls
title Calculator - Subtraction
echo Subtraction:
echo.
echo %subtract1% - %subtract2% = ?
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /a "resultsubtract = %subtract1% - %subtract2%"
echo The answer is %resultsubtract%.
rem %resultsubtract%
ping 1.1.1.1 -n 1 -w 2000 > nul
echo.
echo Type "Back" to enter another problem.
echo Type "Exit" to exit the Calculator.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /p "adda=>"
if %adda%=="Back" goto Input
if %adda%=="back" goto Input
if %adda%==Back goto Input
if %adda%==back goto Input
if %adda%=="Exit" goto Exit
if %adda%=="exit" goto Exit
if %adda%==Exit goto Exit
if %adda%==exit goto Exit
:Multiplication
cls
title Calculator - Multiplication
echo Multiplication:
echo.
echo _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the multiplicand.
ping 1.1.1.1 -n 1 -w 500 > nul
set /p "multiply1=>"
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Multiplication1
:Multiplication1
cls
title Calculator - Multiplication
echo Multiplication:
echo.
echo %multiply1% x _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the multiplier.
ping 1.1.1.1 -n 1 -w 500 > nul
set /p "multiply2=>"
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Multiplication2
:Multiplication2
cls
title Calculator - Multiplication
echo Multiplication:
echo.
echo %multiply1% x %multiply2% = ?
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /a "resultmultiply = %multiply1% * %multiply2%"
echo The answer is %resultmultiply%.
rem %resultmultiply%
ping 1.1.1.1 -n 1 -w 2000 > nul
echo.
echo Type "Back" to enter another problem.
echo Type "Exit" to exit the Calculator.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /p "adda=>"
if %adda%=="Back" goto Input
if %adda%=="back" goto Input
if %adda%==Back goto Input
if %adda%==back goto Input
if %adda%=="Exit" goto Exit
if %adda%=="exit" goto Exit
if %adda%==Exit goto Exit
if %adda%==exit goto Exit
:Division
cls
color 07
title Calculator - Division
set errorlev=0
echo Division:
echo.
echo _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the dividend.
set /p "divide1=>"
ping 1.1.1.1 -n 1 -w 500 > nulping 1.1.1.1 -n 1 -w 1000 > nul
goto Division1
:Division1
cls
title Calculator - Division
set errorlev=0
echo Division:
echo.
echo %divide1% ÷ _
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Enter the divisor.
ping 1.1.1.1 -n 1 -w 500 > nul
set /p "divide2=>"
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Division2
:Division2
cls
title Calculator - Division
set errorlev=0
echo Division:
echo.
echo %divide1% ÷ %divide2% = ?
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /a "resultdivide = %divide1% / %divide2%"
echo The answer is %resultdivide%.
if errorlevel 1 goto Errdiv
if not errorlevel
ping 1.1.1.1 -n 1 -w 2000 > nul
echo.
echo Type "Back" to enter another problem.
echo Type "Exit" to exit the Calculator.
ping 1.1.1.1 -n 1 -w 1000 > nul
set /p "adda=>"
if %adda%=="Back" goto Input
if %adda%=="back" goto Input
if %adda%==Back goto Input
if %adda%==back goto Input
if %adda%=="Exit" goto Exit
if %adda%=="exit" goto Exit
if %adda%==Exit goto Exit
if %adda%==exit goto Exit
:Errdiv
cls
color 0c
ping 1.1.1.1 -n 1 -w 1000 > nul
echo.
echo ERROR : Calculator cannot solve that problem.
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Division
:Exit
cls
ping 1.1.1.1 -n 1 -w 500 > nul
echo.
echo This window will now close.
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
echo Type "Okay" to exit, otherwise type "Cancel" to cancel.
ping 1.1.1.1 -n 1 -w 2000 > nul
set /p "ea=>"
if %ea%=="Okay" goto End2
if %ea%=="okay" goto End2
if %ea%==Okay goto End2
if %ea%==okay goto End2
if %ea%=="Cancel" goto Input
if %ea%=="cancel" goto Input
if %ea%==Cancel goto Input
if %ea%==cancel goto Input
cls
color 0c
ping 1.1.1.1 -n 1 -w 1000 > nul
echo ERROR : That's not a valid choice.
echo.
ping 1.1.1.1 -n 1 -w 500 > nul
echo You have entered "%ea%".
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Exit
:End2
cls
ping 1.1.1.1 -n 1 -w 1000 > nul
echo.
echo Bye!
echo.
ping 1.1.1.1 -n 1 -w 500 > nul
exit`
如您所见,批处理文件太长。 (7 kb):D
在Division2标签:Division2
下,您会看到文字if errorlevel 1 goto Errdiv
而且:
:Errdiv
cls
color 0c
ping 1.1.1.1 -n 1 -w 1000 > nul
echo.
echo ERROR : Calculator cannot solve that problem.
echo.
ping 1.1.1.1 -n 1 -w 1000 > nul
goto Division
我不知道为什么如果我输入红利,然后是除数,它会转到标签,哪里有错误,(Errdiv)。
我也试过这个:%errorlevel%==1
它仍然是错误的事情。
如果只出现错误,是否有办法获取错误标签?
答案 0 :(得分:1)
我不会告诉你,用批处理编写计算器并提供除法功能是没用的,而cmd不能处理浮点数(对于CMD 5/3是1)。 / p>
然而,重点是这一行: > session.get({primary key})
... if {primary key} is in the session, return that object
... otherwise issue the SQL to check if the primary key is in the database
... if the primary key is in the database return that object otherwise None
你正在ping不可达的ip地址1.1.1.1等待1秒。每次执行此命令时,它都会将errorlevel设置为1,因为它无法到达目标。那就是它。
要修复它,您应该ping localhost,因为localhost始终可以访问:JavaCompiler.CompilationTask task = compiler.getTask(
null,
fileManager,
diagnostics,
Arrays.asList("-d", "C:/"),
null,
compilationUnits);
这将ping本地主机2次,ping之间为1秒。因此,如果您想等待x秒,则必须执行ping 1.1.1.1 -n 1 -w 1000 > nul
。您应该替换所有ping 1.1.1.1语句,但不要忘记将所需的时间除以等待1000并添加1。
此外,ping -n 2 localhost> nul
毫无意义。这只是将变量errorlev的值设置为0,但errorlev与errorlevel无关。所以这完全没用。
答案 1 :(得分:-1)
你应该看看this old post。 它描述了与Errorlevels设置相关的文件扩展名.bat和.cmd之间的区别。