Inane Coding Go on, slap that wayward code

8Jun/117

Simple user input in batch files

I was recently playing around with batch scripts (*.bat files) - but what I wanted to do with the script snowballed and I found I needed more functionality, the main one being to be able to execute commands based on user input.

Below is an example of the code I used to do this. This is for Windows NT based batch execution (i.e. any recent computer).


SET /P _inputname= Please enter an input:
IF "%_inputname%"=="OMG" GOTO :they_said_omg

ECHO No 'OMG'... frowny face :(
GOTO :end

:they_said_omg
ECHO You said OMG!

:end

Share