DOS Batch file: A simple prompt to get input from user

person Jason Huangfolder_openHOW-TO, Windowslocal_offer, , , , access_time June 10, 2016

using Set command to set a variable with an input value. /P would tell command line to prompt with a question.

In the example below, command line will prompt you to “Please enter your name:”, then set the value you entered to the variable your_name. In the next line, echo would be printing out the value you entered for variable your_name.

@echo off
set /P your_name="Please enter your name:"
echo Hi, %your_name%

Here’s what the output looks like:

prompt_set

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>