Last active
November 5, 2020 05:40
-
-
Save spikegee/34b863c5614f3d8207dbce2cd10f4e91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:helper_removeOutQuotes | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
set variableName=%1 | |
set variableValue=!%variableName%! | |
set "variableValue=!variableValue:~1,-1!" | |
endlocal & call Set "%~1=%variableValue%" | |
goto:eof | |
rem eg: call :helper_getEchoedValue !cmd! result | |
:helper_getEchoedValue | |
setlocal ENABLEDELAYEDEXPANSION | |
set cmd=%1 | |
rem remove added quotes | |
call:helper_removeOutQuotes !cmd! | |
rem escape pipes | |
set "cmd=!cmd:|=^|!" | |
rem execute command | |
for /F "delims= " %%A in ( '!cmd!' ) do call:helper_getNonNullValue %%A value | |
endlocal & set %~2=%value% | |
goto:eof | |
:helper_getNonNullValue | |
if not [%1]==[] set %~2=%1 | |
goto:eof | |
rem eg: call :helper_countdown 5 "message" | |
:helper_countdown | |
setlocal enableextensions enabledelayedexpansion | |
set num_second=%~1 | |
set message=%~2 | |
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a" | |
FOR /L %%p IN (%num_second%,-1,1) DO ( | |
<nul set /p"=%%p %message%..!CR!" | |
ping 192.0.2.1 -n 1 -w 1000 >nul | |
) | |
goto:eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment