Skip to content

Instantly share code, notes, and snippets.

@danmaq
Created January 14, 2017 05:42
Show Gist options
  • Save danmaq/4044394324057500ac59c5969fae1fc0 to your computer and use it in GitHub Desktop.
Save danmaq/4044394324057500ac59c5969fae1fc0 to your computer and use it in GitHub Desktop.
This Windows batch file confirm yes or no. If arguments exists, run it.
@echo off
rem USAGE: confirm [command: run if confirmed] [args for command]
rem ERRORLEVEL: 0: confirmed, 1: declined
rem EXAMPLE 1: call confirm
rem EXAMPLE 2: confirm msiexec /i foo.msi /qn
setlocal
echo Are you sure you want to run? [y/N]
set /P confirm=""
if "%confirm%"=="Y" goto Y
if "%confirm%"=="y" goto Y
endlocal
exit /b 1
:Y
endlocal
%*
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment