Delicious batch file yumminess (Prompting a user for data in a batch file)

I'll soon be importing another of my blogs called "My Sysadmin Stuff".   These will be labeled with the creative tag "Sysadmin Stuff".  Here is an example of this sort of thing.

Bing sent me to the DosTips.com forum trying to find the magic sauce to redirect STDERR and STDOUT to the same pipe.  That is 2>&1, in case you are wondering.   Since I was there I took a look at the unanswered questions and found one.

A guy asked:
[...]
Am trying to figure out how to make a batch file that will give a prompt to enter a PC name or printer and and perform the ping ******-t command.[...]


I responded:
Like this:


Code:
@echo off
set /P Target=Please enter the name of the host to ping:
ping %Target%



If you want to be really sexy:

Code:
@echo off
:targetprompt
set /P target=Please enter the name of the host to ping:
if "%target%"=="" (
echo A target is required, or you can press CTRL-C to cancel
goto targetprompt
)
ping %target%



Glad to help.
Elizabeth Greene

I like batch files.  This is fun for me.

Comments