Batch file user input ??

R

Richard

Is there a way to capture a keystroke from the user, during a pause, as user
input for conditional branching within a batch file? For example, we would
like to give the user 3 options for executing the IPConfig command.
Depending on which key the user presses during a pause (1,2,3), the file
would execute either an IPConfig, IPConfig /release, or IPConfig /restore
command. Thank you for any help.
 
M

Mark Dormer

@echo off
:top
SET /P test=Enter 1 2 or 3...this can be anything you like

if "%test%" == "1" GOTO label1
if "%test%" == "2" GOTO label2
if "%test%" == "3" GOTO label3
if "%test%" GTR "3" GOTO top

:label1
echo %test%
goto :EOF

:label2
echo %test%
goto :EOF

:label3
echo %test%
goto :EOF


Regards
Mark Dormer
 
P

Pegasus \(MVP\)

You might want to add an "exit" response, e.g. when
the user enters a blank, plus some code to cater for
responses other than numbers:

:top
if "%test%"=="" goto :eof
if "%test%" == "1" GOTO label1
if "%test%" == "2" GOTO label2
if "%test%" == "3" GOTO label3
GOTO top
 
B

Blue Max

Thanks, Mark, if you are still out there. I lost this message thread in a
system reinstall and just found it today. Thanks!

********************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top