批处理:在我的代码循环期间,它停止设置变量.欢迎所有帮助 [英] Batch: During my code loop it stops setting a variable. All Help Welcome

查看:16
本文介绍了批处理:在我的代码循环期间,它停止设置变量.欢迎所有帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

goto time

:time
set tm=%time%
set hh=%tm:~0,2%
set mm=%tm:~3,2%
set ss=%tm:~6,2%
set ms=%tm:~7,2%
goto date

:date
set dt=%date%
set wd=%dt:~0,3%
set mh=%dt:~4,2%
set dy=%dt:~6,2%
set yr=%dt:~8,4%
goto scheduletimes

:scheduletimes
goto hour1
:hour1
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a "HH"="%%b"
if %HH% equ 6 goto minutes1
pause
goto time
:minutes1
for /f "tokens=1*delims=0" %%a in ("$0%mm%") do set /a "MM"="%%b"
if "%MM%"=="00" goto seconds1
pause
goto time
:seconds1
for /f "tokens=1*delims=0" %%a in ("$0%ss%") do set /a "SS"="%%b"
if %SS% lss 10 goto day1
pause
goto time

:day1
echo success
echo %hh%
echo %mm%
echo %ss%
pause 
goto time

正如你们所看到的,这是一个时间检查循环.看看时间是不是6:10:>10.基本上我的问题是它运行良好,直到它到达那个时间时执行命令.只要在本节中变为 <10 秒:

As you guys can see this is a time check loop. Seeing if the time is 6:10:>10. Basically what my problem is though is that it runs fine until it executes the command when it hits that time. As soon as it becomes <10 seconds in this section:

:minutes1
for /f "tokens=1*delims=0" %%a in ("$0%mm%") do set /a "MM"="%%b"
if %MM% equ 0 goto seconds1

它停止将 MM 设置为 %mm%,并给我一个 Missing Operand 错误.

it stops setting MM to %mm% and it gives me a Missing Operand error.

如果能在第一次运行后继续工作,我们将不胜感激.

Any help would be appreciated to get it to continue working after the first run.

(是的,我知道有停顿,没有@echo 关闭,这是出于调试目的.它在关闭@echo 时也没有停顿)

(Yes I do know there are pauses and no @echo off, This is for debugging purposes. It does it with the @echo off and without the pauses too)

记录

C:Userskrato_000Desktop>goto scheduletimes

C:Userskrato_000Desktop>goto hour1

C:Userskrato_000Desktop>for /F "tokens=1*delims=0" %a in ("$0 6") do set /a "
HH"="%b"

C:Userskrato_000Desktop>set /a "HH"=" 6"

C:Userskrato_000Desktop>if 6 EQU 6 goto minutes1

C:Userskrato_000Desktop>for /F "tokens=1*delims=0" %a in ("$000") do set /a "
MM"="%b"

C:Userskrato_000Desktop>set /a "MM"=""
Missing operand.

C:Userskrato_000Desktop>if "00" == "00" goto seconds1

C:Userskrato_000Desktop>for /F "tokens=1*delims=0" %a in ("$019") do set /a "
SS"="%b"

C:Userskrato_000Desktop>set /a "SS"="19"

C:Userskrato_000Desktop>if 19 LSS 10 goto day1

C:Userskrato_000Desktop>pause
Press any key to continue . . .

推荐答案

请注意,批处理不区分 %mm%%MM%.试试这个:

Please note, batch does not differentiate between %mm%and %MM%. Try this:

:minutes1
set /a min=0
for /f "tokens=1*delims=0" %%a in ("$0%mm%") do set /a min=%%b 2>nul
echo %min%
if %min% equ 0 goto seconds1

这篇关于批处理:在我的代码循环期间,它停止设置变量.欢迎所有帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆