我需要在文件中计算批处理脚本的执行次数。
在linux shell中,这就像
counter=`cat buildnumber.txt`;
counter=`echo $counter+1|bc`
echo $counter > buildnumber.txt
但是如何在批处理文件中执行此操作?
答案 0 :(得分:3)
完全相同的逻辑,但使用批处理命令:
<buildnumber.txt set /p counter=
set /a counter +=1
echo %counter%>buildnumber.txt
答案 1 :(得分:0)
这是我计算批处理脚本执行次数的方法:
@echo off
Setlocal enabledelayedexpansion
Title Count the number of times my BATCH file is run
Mode Con Cols=60 lines=3 & color 0E
set /a count=1
set "FileCount=%tmp%\%~n0.txt"
If Not exist "%FileCount%" (
echo !count! > "%FileCount%"
) else (
For /F "tokens=*" %%a in ('Type "%FileCount%"') Do (
set /a count=!count! + %%a
echo !count! > "%FileCount%"
)
)
echo.
echo This batch script is running for "!count! time(s)"
EndLocal
pause>nul