我正在创建一个提醒,当一段时间过去后会弹出一个文本文件,我想要实现的是倒计时(在即将到来的循环开始之前剩下多少秒和分钟)。一切似乎都很顺利,直到我尝试将分钟和秒组合成一行的部分。它在行"300 not expected here"
之后给出了echo Left (in minutes): %leftMinutes%
错误。任何和所有的帮助将不胜感激。
:Start
set /a wait = 0
set /a waitMinutes = 0
set /a left59 = %real_time% - 59 :: %real_time% is the inputed minutes,
:: converted to seconds.
cls
color 0a
for /f "delims=" %%a in (Notes.txt) do (
set notes=%%a
)
cd %~dp0/Notes
start Notes.txt
goto Loop
:Loop
cls
echo Waiting for %answer_time% minutes.
echo.
set /a leftSeconds = %real_time% - %wait%
echo Left (in seconds): %leftSeconds%
set /a leftMinutes = %answer_time% - %waitMinutes%
echo Left (in minutes): %leftMinutes%
if %wait% LSS %left59% ( :: Checks if there's one more minute left in
:: %real_time%.
if %wait% GEQ %left59% ( :: Checks if there's no more minutes left
:: in %real_time%.
echo Left (both): %leftSeconds%
)
echo Left (both): %leftMinutes% and %leftSeconds%
)
timeout -t 1 -nobreak > nul
set /a wait += 1
if %wait% == 60 (
set /a waitMinutes += 1
)
if not %wait% == %real_time% (
goto Loop
)
if %wait% GEQ %real_time% (
if %waitMinutes% == %answer_time% (
taskkill -f -im Notepad.exe
goto Start
)
)
答案 0 :(得分:2)
:label
nor :: label-like comment
inside a command block enclosed in ()
parentheses;使用REM
代替::
)
个命令中的所有echo
。即使在echo
中,未转义的右括号仍然是右括号。例如,使用
而不是echo Left (both): %leftSeconds%
echo Left (both^): %leftSeconds%
rem ^ note the caret
echo Left (both^): %leftMinutes% and %leftSeconds%
rem ^ note the caret
请阅读Syntax : Escape Characters, Delimiters and Quotes文章。
脚本中的最小更改(可能不完整)如下:
if %wait% LSS %left59% ( REM Checks if there's one more minute left in
REM %real_time%.
if %wait% GEQ %left59% ( REM Checks if there's no more minutes left
REM in %real_time%.
echo Left (both^): %leftSeconds%
)
echo Left (both^): %leftMinutes% and %leftSeconds%
)