我正在尝试批量制作一个倒数计时器,到目前为止,我已经有了这个
:timer
set time=0
:time
set /a time=%time%+1
ping localhost -n 2 >nul
goto time问题是,我想让它在同一批处理文件中发生另一个事件的同时运行。我该怎么做呢?
发布于 2014-12-06 15:04:27
你想知道执行你的批处理脚本需要多长时间吗?如果已安装PowerShell,则可以使用Measure-Command cmdlet。
将此文件另存为timeit.bat
@echo off
>~timeit-%~n1.bat echo(%*
powershell "Measure-Command {Start-Process ~timeit-%~n1.bat -Wait}"
del ~timeit-%~n1.bat然后,当你想给某个东西的执行计时,比如说,systeminfo,只要timeit systeminfo就行了。
如果您更喜欢非powershell解决方案(因为powershell在每个窗口会话的第一次运行中需要几秒钟来启动自己),这里有一个更快的batch / JScript混合解决方案(more info)。它还会在同一个窗口中执行该命令,而powershell解决方案会为您的命令创建一个新窗口。将此文件另存为timer.bat
@if (@a==@b) @end /* begin multiline JScript comment
:: timer.bat command args
:: measures execution time of a command
@echo off & setlocal
if "%~1"=="" (
echo Usage: %~nx0 command args
goto :EOF
)
cscript /nologo /e:JScript "%~f0" %*
goto :EOF
:: end batch portion / begin JScript */
var osh = new ActiveXObject('wscript.shell'), cmd = [], b4 = new Date();
for (var i=0; i<WSH.Arguments.length; i++) {
var arg = WSH.Arguments(i);
cmd.push(/\s/.test(arg) ? '"' + arg + '"' : arg);
}
var exe = osh.Exec('cmd /c ' + cmd.join(' '));
while(!exe.StdOut.AtEndOfStream) WSH.Echo(exe.StdOut.ReadLine())
var x = (new Date() - b4) / 1000,
d = Math.floor(x / 86400),
d = d ? d + ' days ' : '',
h = ('0' + (Math.floor(x / 3600) % 24)).slice(-2),
m = ('0' + (Math.floor(x / 60) % 60)).slice(-2),
s = Math.floor(x % 60) + x % 1,
s = (s < 10) ? '0'+s : s;
WSH.Echo('\r\nExecution completed in ' + d + h + ':' + m + ':' + s);https://stackoverflow.com/questions/27327177
复制相似问题