Created
February 16, 2017 03:43
-
-
Save x5lcfd/1acc4e4ca252967de8aa1b6f78d25fd5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
:: setvar varname cmd | |
:: Set VARNAME to the output of CMD | |
:: Triple escape pipes, eg: | |
:: setvar x dir c:\ ^^^| sort | |
:: ----------------------------- | |
:: http://stackoverflow.com/a/25954264/6181205 | |
@echo off | |
SETLOCAL | |
:: Get command from argument | |
for /F "tokens=1,*" %%a in ("%*") do set cmd=%%b | |
:: Get output and set var | |
for /F "usebackq delims=" %%a in (`%cmd%`) do ( | |
ENDLOCAL | |
set %1=%%a | |
) | |
:: Show results | |
SETLOCAL EnableDelayedExpansion | |
echo %1=!%1! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment