[BATCH/.Bat文件]帮助计数错误吗? [英] [BATCH / .Bat files]Help counting up error?

查看:49
本文介绍了[BATCH/.Bat文件]帮助计数错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我试图让批处理文件每1秒计数一次,但是它可以部分地..

well im trying to have a batch file to count up every 1 second but it comes that it partially can ..

如果秒数少于10秒,我所做的代码将显示为01,02 ..而不是1,2 ..

the code i did was if seconds are lower than 10 than they will be displayed like 01,02 .. not like 1,2 ..

这是完整文件

@Echo off
set m=00
set m1=00 //m1 being minutes and m being seconds
echo %m% 
:clock
set /a m+=1
if %m% LSS 10 ( if %m% GTR 0 ( set m=0%m%)) ELSE (break) // for detecting if less than 10 found out that break doesnt do any job
if %m% GTR 60 (set /a m1+=1) //60 seconds will make it a minute .. 
if %m1% LSS 10  ( if %m1% GTR 0 (set m1=0%m1% ) ) //same detecting for minutes..
echo %m% : %m1% // display time ss:mm


ping 1.1.1.1 -n 1 -w 100 > nul //stop the file for 100 (1 secs)
goto clock // go to your looping clock

但是问题出在,而不是从00到10 ....每次都会在08重置.这是关于enabledelayedexpansion吗?我如何解决/简化它,而无需下载外部.exe文件放入文件夹

but the problem is instead of counting from 00 to 10 .... it resets at 08 everytime.. is this about enabledelayedexpansion ?? and how can i fix / simplisize it without downloading external .exe files to put in the folder

奇怪的是,以下代码可以正常工作

the weird thing is the following code works without no problems

if %m% LSS 10 ( echo 0%m%) else ( echo %m%)

但是,如果我像上装那样使用它,我将需要写几分钟甚至几小时来写..

but if i use it like the top i would need to go complicated to write minutes or even hours ..

推荐答案

批处理软件时钟:

@echo off
setlocal
set "s=0"
set "m=0"
:clock
set "mm=00%m%"
set "ss=00%s%"
echo %mm:~-2% : %ss:~-2%
set /a "s+=1"
if %s% gtr 59 set "s=0" & set /a "m+=1"
ping 192.0.2.2 -n 1 -w 1000 >nul
goto clock
endlocal

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