Saturday, October 31, 2020

 https://www.tutorialspoint.com/batch_script/index.htm

https://en.wikibooks.org/wiki/Windows_Batch_Scripting



Ex 1:
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%

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Lập trình hệ thống nhúng Linux . Powered by Luong Duy Ninh -