精选栏目: 装机必备 专题大全 常用工具 系统集锦

Windows批处理脚本计算外部程序消耗的时长

栏目: 批处理 已有人学习|编辑:星期八; 来源:转载;

引言

很少写Windows下的批处理命令脚本,既然遇到了它的用法,就先记下来吧,供自己和大家参考。没啥技术含量,直接上代码。


简单直接的脚本


@echo offset /a StartS=%time:~6,2% set /a StartM=%time:~3,2%set /a startH=%time:~0,2%echo 开始时间:%time%ping 192.168.1.1 set /a EndS=%time:~6,2% set /a EndM=%time:~3,2% set /a EndH=%time:~0,2%echo 结束时间:%time%set /a  diffS_=%EndS%-%StartS%set /a  diffM_=%EndM%-%StartM%set /a  diffH_=%EndH%-%StartH%set /a cost=%diffH_%*3600 + %diffM_%*60 + %diffs_%echo 总共花费时间 : %cost% 秒


通过调用函数实现的脚本


@echo offset logfile="caltime-%time:~0,2%-%time:~3,2%-%time:~6,2%.txt"set output="yes"set cmd="ping 192.168.1.1 -n 5"call :execute %cmd%set cmd="ping 192.168.1.100 -n 5"call :execute %cmd%:executeif "%~1" == "" (goto :eof)echo =============================================================================== >>%logfile%echo ===============================================================================set /a StartS=%time:~6,2% set /a StartM=%time:~3,2%set /a startH=%time:~0,2%echo 开始时间:%date% %time% >>%logfile%echo 开始时间:%date% %time%echo 调用命令: %~1 >>%logfile%echo 调用命令: %~1 if %output% == "yes" (%~1 >>%logfile% 2>&1) else %~1set /a EndS=%time:~6,2% set /a EndM=%time:~3,2% set /a EndH=%time:~0,2%echo 结束时间:%date% %time% >>%logfile%echo 结束时间:%date% %time% set /a  diffS_=%EndS%-%StartS%set /a  diffM_=%EndM%-%StartM%set /a  diffH_=%EndH%-%StartH%if %diffH_% lss 0 (set /a diffH_=%diffH_%+24)set /a cost=%diffH_%*3600 + %diffM_%*60 + %diffs_%echo 花费时间: %cost% 秒 >>%logfile%echo 花费时间: %cost% 秒echo =============================================================================== >>%logfile%echo ===============================================================================goto :eof


收藏 赞() 踩()
本文地址:http://www.zhishiwu.com/bc/bat/35354.html
本文标签:windows 批处理脚本 外部程序消耗时长
评论