Skip to content

Instantly share code, notes, and snippets.

@davidruhmann
Created November 6, 2014 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidruhmann/32bb54dbe191a2434b8f to your computer and use it in GitHub Desktop.
Save davidruhmann/32bb54dbe191a2434b8f to your computer and use it in GitHub Desktop.
SO26787012.bat
@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