发布时间:2015-03-27 10:43:28作者:知识屋
引言 很少写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
2011-02-18
批处理教程之——字符串查找:find
DOS批处理应用循环拷贝文件到固定目录的子目录
批处理中的时间计算详解
VBS对Office软件Word、Excel等的操作实例
如何进入DOS系统/界面
dos下通过wmic命令查看硬盘和内存/CPU信息(windows自带命令查看
一份比较详细的DOS命令说明【DNJSB整理】
浅谈批处理for命令中的变量扩展
dos(cmd)中删除、添加、修改注册表命令