[英]Timing a process with windows batch script
嗨,谢谢你,
我是开发批处理文件的新手,但是我现在正在尝试编写一个bat文件,它将创建并写入ldif文件。 我从简单的第一开始。 我还需要对过程进行计时,因为它可能变得更加复杂,并且以后可能需要进行软件比较(例如,稍后与bat对比Java)。
现在我只有这个:
@ echo "LDIF Generator"
@ echo off
:: *** Enter the file here "within the double quotes"
set fileName="test.ldif"
:: *** If file exists, then erase all previous content
::if exist %fileName% ECHO Erase the file >%fileName%
echo Hello>%fileName%
echo Created LDIF File %fileName%
set /a sum = 0
for /L %%A in (1,1,5) do (
echo %%A>>%fileName% set a/ sum = "%sum% + %%A"
)
echo sum is %sum%
pause
我目前正在尝试弄清楚如何将一些数字加起来并安排时间。
到目前为止,它给了我这个输出:
Hello
1 set a/ sum = 0 + 1
2 set a/ sum = 0 + 2
3 set a/ sum = 0 + 3
4 set a/ sum = 0 + 4
5 set a/ sum = 0 + 5
在cmd上的总和是“ 0”
我正在尝试显示当前的迭代总和,并在结束时回显最后的总和以及执行此操作所需的时间。
@ECHO OFF &SETLOCAL
set /a sum = 0
for /L %%A in (1,1,5) do (
set /a sum+=%%A
)
echo sum is %sum%
sum is 15
使用Endoro的代码或类似的代码。 那比较简单。 但是作为解释……使用类似您的代码,您需要启用elayedexpansion并使用! 而不是FOR或IF构造中的%来指定您要使用变量sum的运行时值而不是加载时值。
setlocal enabledelayedexpansion
set /a sum = 0
for /L %%A in (1,1,5) do (
echo %%A>>%fileName% set a/ sum = "!sum! + %%A"
)
echo sum is %sum%
endlocal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.