- Back to Home »
- Windows Batch Script »
- Windows Batch Script Tutorial
Saturday, October 31, 2020
https://www.tutorialspoint.com/batch_script/index.htm
https://en.wikibooks.org/wiki/Windows_Batch_Scripting
call :myhead 2
exit /b
:: Function myhead
:: ===============
:: %1 - lines count
:myhead
setlocal EnableDelayedExpansion
set counter=1
set mycmd=wmic os get LocalDateTime
for /f "tokens=*" %%i in ('%mycmd%') do (
echo %%i
set /a counter=!counter!+1
if !counter! gtr %1 exit /b
)
exit /b
Ex2:
setlocal EnableDelayedExpansion
set counter=1
set mycmd=wmic os get LocalDateTime
for /f "tokens=*" %%i in ('%mycmd%') do (
::echo %%i
set myresult=%%i
::echo !myresult!
set /a counter=!counter!+1
if !counter! gtr 2 goto end_wmic
)
:end_wmic
echo %myresult%