批量结果我“回声”而不是正确的结果

时间:2015-06-14 21:11:47

标签: batch-file cmd

我对下一个代码

有点问题
@Echo off
Title STARTING
cls
echo.
echo Checking running services...
echo.
timeout /t 2 /nobreak >NUL
tasklist /fi "imagename eq cmd.exe" /v | find /I /N "DATABASESERVER" >NUL
if "%ERRORLEVEL%"=="1" (
cls
echo.
echo Database is not running, now will start!
echo.
start database.bat
echo Database is running! 
echo.
timeout /t 4 /nobreak >NUL
)
tasklist /fi "imagename eq cmd.exe" /v | find /i /n "ARMASERVER" >NUL
if "%errorlevel%"=="1" (
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
   set /A "ora=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
)
echo %ora%
pause
cls
echo.
echo Server is not running, now will start!
echo.
start arma.bat
title EPOCHSERVER
timeout /t 39 /nobreak >NUL
)

问题是“echo%ora%”它给我结果“Echo off”而不是以秒为单位的时间值

有什么问题?

提前谢谢!

2 个答案:

答案 0 :(得分:1)

此时

Minitest::UnexpectedError: NoMethodError: undefined method `type' for nil:NilClass 为空,这意味着正在执行的命令只是%ora%,它返回echo的状态。

您确定echo行上的引号应该在那里吗?

具有更好批处理技能的人会说出来;我不想冒险用半受教育的猜测误导你。

与此同时,我建议您直接在命令行上使用该行,直到获得预期的结果。请记住将批处理脚本之外的set字符加倍。

答案 1 :(得分:1)

您需要enable delayed expansion

tasklist /fi "imagename eq cmd.exe" /v | find /i /n "ARMASERVER" >NUL
if "%errorlevel%"=="1" (
  for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
     set /A "ora=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
  )
  echo percent inside ^(^)=%ora%
  setlocal enabledelayedexpansion
    echo exclamation=!ora!
  endlocal
)
echo percent  outside ^(^)=%ora%

输出:

==>D:\bat\SO\30834591.bat
percent inside ()=
exclamation=214860
percent  outside ()=214860

==>