How to accept user input command in batch file?
5,828
Use set /P
to get the user's input into a variable, then run the variable as if it's a command:
@echo off
set /P CommandVar=Command?
%CommandVar%
From set /?
:
The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty.
Related videos on Youtube
Author by
user3152251
Updated on September 18, 2022Comments
-
user3152251 over 1 year
I would like to write a batch file in which the user input would be run as a command, essentially functioning like command prompt.
Example:
batch file is run: user input: echo hello program output: hello
How would I implement this?
-
Shekhar over 9 years
-
-
LPChip over 9 yearsOh wow, I never knew you could actually execute a command like that. Thanks. I learned something today. :)