Board logo

标题: 批处理IF怎样判断多个条件的时间值? [打印本页]

作者: bobgjs    时间: 2011-5-16 11:41     标题: 批处理IF怎样判断多个条件的时间值?

本帖最后由 bobgjs 于 2011-5-16 14:06 编辑

我想让IF判断多个时间值,按不同的时间执行相应的操作,我测试无效,请求帮助。
初学者,请勿见笑。
  1. @echo off
  2. :IF
  3. echo.
  4. echo.
  5. echo      %time:~0,5%
  6. if %time:~0,5% EQU "11:30" goto :tas
  7. if %time:~0,5% EQU "13:32" goto :tas
  8. if %time:~0,5% EQU "15:34" goto :tas
  9. if %time:~0,5% EQU "16:36" goto :tas
  10. if %time:~0,5% EQU "20:38" goto :shut
  11. ping 127.1 -n 10 >nul
  12. cls
  13. goto :IF
  14. :tas
  15. taskkill /f /im QQ.exe
  16. ping 127.1 -n 10 >nul
  17. start F:\QQ\Bin\QQ.exe
  18. goto :IF
  19. :shut
  20. echo "shutdown -r -f -t 0"
复制代码
我改了,仍然不行,请求赐教啊。。。。。。。。
我这样写是对的吗?
作者: hanyeguxing    时间: 2011-5-16 12:10

if %time:~0,3% EQU 11:30 goto :tas

永远不会执行:
1,11:30是5个字符,%time:~0,3%是3个字符,怎么可能相等呢
2,%time:~0,3%中第一个字符可能为空格,所以被比较双方都要加引号
作者: wolonga123    时间: 2011-5-16 12:47

taskkill /f /im QQ.exe这句好像是taskkill  /im QQ.exe /f
作者: liaobiaoxing    时间: 2011-5-16 12:49

楼上,测试过就知道,无区别的……
作者: hanyeguxing    时间: 2011-5-16 13:18

  1. @echo off
  2. for %%a in (0 2 4 6) do set ""#11:3%%a"=="
  3. set ""$11:38"=="
  4. start F:\工作\EasyBoot\Tencent\QQ\Bin\QQ.exe
  5. :IF
  6. cls&echo;&echo;     %time:~0,5%
  7. if defined "$%time:~0,5%" shutdown -r -f -t 0
  8. if defined "#%time:~0,5%" (
  9. taskkill /f /im QQ.exe
  10. ping 127.1 -n 10 >nul
  11. start F:\工作\EasyBoot\Tencent\QQ\Bin\QQ.exe
  12. goto:IF
  13. )
  14. ping 127.1 -n 10 >nul
  15. goto:IF
复制代码

作者: bobgjs    时间: 2011-5-16 13:26

5# hanyeguxing

如果时间8:00  12:00 16:00 20:00 。。。。
我怎么改你的代码?
作者: Batcher    时间: 2011-5-16 13:35

3# wolonga123


大部分命令的选项对位置没有要求
作者: hanyeguxing    时间: 2011-5-16 16:14

6# bobgjs


for %%a in (0 2 4 6) do set ""#11:3%%a"=="
set ""$11:38"=="
改为:
for %%a in (08 12 16 20) do set ""#%%a:00"=="
set ""$21:00"=="




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2