Created
November 6, 2014 20:00
-
-
Save davidruhmann/32bb54dbe191a2434b8f to your computer and use it in GitHub Desktop.
SO26787012.bat
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
@echo off | |
setlocal EnableDelayedExpansion | |
call :Input MyVar "Enter your string " | |
call :Write MyVar | |
echo !MyVar! | |
set MyVar | |
endlocal | |
exit /b 0 | |
:Input <Var> [Prompt] | |
set /p "%~1=%~2" | |
rem if defined %~1 set "%~1=%Input:"=%" | |
if not defined %~1 = goto Input | |
rem endlocal & set "%~1=%Input%" & exit /b 0 | |
exit /b 0 | |
:Input2 <Var> [Prompt] | |
setlocal DisableDelayedExpansion | |
set "Input=" | |
set /p "Input=%~2" | |
if defined Input set "Input=%Input:"=%" | |
if not defined Input goto Input | |
endlocal & set "%~1=!Input!" & exit /b 0 | |
:Write <Var> | |
setlocal EnableDelayedExpansion | |
set /p "=!%~1!" <nul | |
echo. | |
echo !%~1! | |
endlocal & exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment