中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
« [1] [2] [3] [4] »
作者:
标题: [已结]检测系统存活的程式 上一主题 | 下一主题
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 31 楼』:  

请问在哪里加pause 可以测试

2008-11-25 17:41
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 32 楼』:  

我不是加了pause了么?



2008-11-25 18:04
查看资料  发短消息 网志   编辑帖子  回复  引用回复
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 33 楼』:  

但是运行没有停顿,不能测试,请指教

2008-11-25 20:03
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 34 楼』:  

那你就在每一句后面都加pause



2008-11-25 20:08
查看资料  发短消息 网志   编辑帖子  回复  引用回复
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 35 楼』:  

我测试以后
结果如下:
FileDay: 2008 11 25 19 59 mFileDay
FileDay2Minutes: 20460719

没有进行判定?

2008-11-25 20:33
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 36 楼』:  

你家里的系统不是xp么?日期时间的格式跟23楼一样么?每一句都加pause结果就输出了35楼这么点结果?



2008-11-25 22:51
查看资料  发短消息 网志   编辑帖子  回复  引用回复
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 37 楼』:  

哦 明白了
我明天去公司去测试下

2008-11-25 23:16
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 38 楼』:  

如果需要在家里的XP系统上测试,请根据实际日期时间的格式修改一下系统变量截取的那部分代码。



2008-11-25 23:32
查看资料  发短消息 网志   编辑帖子  回复  引用回复
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 39 楼』:  

经过测试
结果如下:
FileDay: 2008 11 25 04 35p mFileDay
FileDay2Minutes: 20460515

还是没有判定,斑竹指教

2008-11-26 09:11
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 40 楼』:  

每一句都加pause结果就输出了39楼这么点结果?
开始,运行,cmd,yourfile.bat,有没有报错信息?



2008-11-26 09:48
查看资料  发短消息 网志   编辑帖子  回复  引用回复
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 41 楼』:  

@echo off
pause
set SrcFile=D:\a.txt
pause
for /f "skip=5 tokens=1-2 delims= " %%a in ('dir /tw "%SrcFile%"') do (
pause
  set "FileDay=%%a %%b"
pause
  goto :compare
pause
)
:compare
pause
REM set "FileDay=2008/11/25 20:57"
call :DateToMins %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
pause
echo FileDay: %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay2Minutes: %mFileDay%
REM set "mydate=星期二 2008/11/25 15:53:54.40"
call :DateToMins %date:~4,4% %date:~9,2% %date:~12,2% %time:~15,2% %time:~18,2% mToday
pause
echo Today: %date:~4,4% %date:~9,2% %date:~12,2% %time:~15,2% %time:~18,2% mToday
echo Today2Minutes: %mToday%
set /a mMinus=mToday-mFileDay
pause
echo Minus: %mMinus%
if %mMinus% gtr 5 (
  echo "The system is down"
  pause
) else (
  echo "The system is running"
  pause
)
pause
goto :eof
pause
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DateToMins %yy% %mm% %dd% %hh% %mm% result
::
:: By:   Ritchie Lawrence, updated 2003-04-03. Version 1.1
::
:: Func: Returns the number of elapsed minutes since 1970-01-01 00:00
::       for a given date. For NT4/2K/XP/2003
::
:: Args: %1 years to convert, 2 or 4 digit (by val)
::       %2 months to convert, 1/01 to 12, leading zero ok (by val)
::       %3 days to convert, 1/01 to 31, leading zero ok (by val)
::       %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be
::          suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val)
::       %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val)
::       %6 var to receive number of elapsed minutes (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
pause
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
pause
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
pause
set /a dd=100%dd%%%100,mm=100%mm%%%100
pause
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
pause
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
pause
if 1%hh% LSS 20 set hh=0%hh%
pause
if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
pause
if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
pause
if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
pause
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
pause
endlocal&set %6=%j%&goto :EOF
pause



结果还是:
FileDay: 2008 11 25 04 35p mFileDay
FileDay2Minutes: 20460515

2008-11-26 09:57
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 42 楼』:  


set SrcFile=D:\a.txt
for /f "skip=5 tokens=1-2 delims= " %%a in ('dir /tw "%SrcFile%"') do (
  set "FileDay=%%a %%b"
  goto :compare
)
:compare
REM set "FileDay=2008/11/25 20:57"
call :DateToMins %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay: %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay2Minutes: %mFileDay%
REM set "mydate=星期二 2008/11/25 15:53:54.40"
call :DateToMins %date:~4,4% %date:~9,2% %date:~12,2% %time:~15,2% %time:~18,2% mToday
echo Today: %date:~4,4% %date:~9,2% %date:~12,2% %time:~15,2% %time:~18,2% mToday
echo Today2Minutes: %mToday%
set /a mMinus=mToday-mFileDay
echo Minus: %mMinus%
if %mMinus% gtr 5 (
  echo "The system is down"
) else (
  echo "The system is running"
)
pause
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DateToMins %yy% %mm% %dd% %hh% %mm% result
::
:: By:   Ritchie Lawrence, updated 2003-04-03. Version 1.1
::
:: Func: Returns the number of elapsed minutes since 1970-01-01 00:00
::       for a given date. For NT4/2K/XP/2003
::
:: Args: %1 years to convert, 2 or 4 digit (by val)
::       %2 months to convert, 1/01 to 12, leading zero ok (by val)
::       %3 days to convert, 1/01 to 31, leading zero ok (by val)
::       %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be
::          suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val)
::       %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val)
::       %6 var to receive number of elapsed minutes (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
endlocal&set %6=%j%&goto :EOF
把完整结果贴出来看看



2008-11-26 10:58
查看资料  发短消息 网志   编辑帖子  回复  引用回复
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 43 楼』:  

结果如下:
d:\Documents and Settings\cy_pjhuang\桌面>set SrcFile=D:\a.txt

d:\Documents and Settings\cy_pjhuang\桌面>for /F "skip=5 tokens=1-2 delims= " %a in ('dir /tw "D:\a.txt"') do (
set "FileDay=%a %b"  
goto :compare
)

d:\Documents and Settings\cy_pjhuang\桌面>(
set "FileDay=2008/11/25 04:35p"  
goto :compare
)

d:\Documents and Settings\cy_pjhuang\桌面>REM set "FileDay=2008/11/25 20:57"

d:\Documents and Settings\cy_pjhuang\桌面>call :DateToMins 2008 11 25 04 35p mFileDay

d:\Documents and Settings\cy_pjhuang\桌面>setlocal ENABLEEXTENSIONS

d:\Documents and Settings\cy_pjhuang\桌面>set yy=2008  & set mm=11  & set dd=25  & set hh=04  & set nn=35p

d:\Documents and Settings\cy_pjhuang\桌面>if 12008 LSS 200 if 12008 LSS 170 (set yy=202008 )  else (set yy=192008 )

d:\Documents and Settings\cy_pjhuang\桌面>set /a dd=10025%100,mm=10011%100

d:\Documents and Settings\cy_pjhuang\桌面>set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2

d:\Documents and Settings\cy_pjhuang\桌面>set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633

d:\Documents and Settings\cy_pjhuang\桌面>if 104 LSS 20 set hh=004

d:\Documents and Settings\cy_pjhuang\桌面>if {p} EQU {p} if "04" NEQ "12" set hh=104  & set/a hh-=88

d:\Documents and Settings\cy_pjhuang\桌面>if {p} EQU {a} if "16" EQU "12" set hh=00

d:\Documents and Settings\cy_pjhuang\桌面>if {p} GEQ {a} set nn=35

d:\Documents and Settings\cy_pjhuang\桌面>set /a hh=10016%100,nn=10035%100,j=j*1440+hh*60+nn

d:\Documents and Settings\cy_pjhuang\桌面>endlocal & set mFileDay=20460515  & goto :EOF

d:\Documents and Settings\cy_pjhuang\桌面>echo FileDay: 2008 11 25 04 35p mFileDay
FileDay: 2008 11 25 04 35p mFileDay

d:\Documents and Settings\cy_pjhuang\桌面>echo FileDay2Minutes: 20460515
FileDay2Minutes: 20460515

d:\Documents and Settings\cy_pjhuang\桌面>REM set "mydate=星期二 2008/11/25 15:53:54.40"

d:\Documents and Settings\cy_pjhuang\桌面>call :DateToMins 2008 11 26   mToday

d:\Documents and Settings\cy_pjhuang\桌面>setlocal ENABLEEXTENSIONS

d:\Documents and Settings\cy_pjhuang\桌面>set yy=2008  & set mm=11  & set dd=26  & set hh=mToday  & set nn=

d:\Documents and Settings\cy_pjhuang\桌面>if 12008 LSS 200 if 12008 LSS 170 (set yy=202008 )  else (set yy=192008 )

d:\Documents and Settings\cy_pjhuang\桌面>set /a dd=10026%100,mm=10011%100

d:\Documents and Settings\cy_pjhuang\桌面>set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2

d:\Documents and Settings\cy_pjhuang\桌面>set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633

d:\Documents and Settings\cy_pjhuang\桌面>if 1mToday LSS 20 set hh=0mToday

d:\Documents and Settings\cy_pjhuang\桌面>if {~2,1hhhh&set/a hh-=88

2008-11-26 11:05
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 44 楼』:  


@echo off
set SrcFile=D:\a.txt
for /f "skip=5 tokens=1-2 delims= " %%a in ('dir /tw "%SrcFile%"') do (
  set "FileDay=%%a %%b"
  goto :compare
)
:compare
REM set "FileDay=2008/11/25 20:57"
call :DateToMins %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay: %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay2Minutes: %mFileDay%
REM set "mydate=星期二 2008/11/25 15:53:54.40"
call :DateToMins %date:~4,4% %date:~9,2% %date:~12,2% %time:~0,2% %time:~3,2% mToday
echo Today: %date:~4,4% %date:~9,2% %date:~12,2% %time:~0,2% %time:~3,2% mToday
echo Today2Minutes: %mToday%
set /a mMinus=mToday-mFileDay
echo Minus: %mMinus%
if %mMinus% gtr 5 (
  echo "The system is down"
) else (
  echo "The system is running"
)
pause
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DateToMins %yy% %mm% %dd% %hh% %mm% result
::
:: By:   Ritchie Lawrence, updated 2003-04-03. Version 1.1
::
:: Func: Returns the number of elapsed minutes since 1970-01-01 00:00
::       for a given date. For NT4/2K/XP/2003
::
:: Args: %1 years to convert, 2 or 4 digit (by val)
::       %2 months to convert, 1/01 to 12, leading zero ok (by val)
::       %3 days to convert, 1/01 to 31, leading zero ok (by val)
::       %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be
::          suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val)
::       %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val)
::       %6 var to receive number of elapsed minutes (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
endlocal&set %6=%j%&goto :EOF




2008-11-26 11:52
查看资料  发短消息 网志   编辑帖子  回复  引用回复
win007
初级用户





积分 45
发帖 44
注册 2008-11-22
状态 离线
『第 45 楼』:  

测试成功,万分感谢斑竹~

2008-11-26 13:23
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
« [1] [2] [3] [4] »
请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: