User inputs in Batch (.bat) files
I wanted to know how we can create a batch file with user inputs in it. How does they work? I have seen my senior working on it, creating batch files with user inputs and then making installation of OS easier by which the bootable floppy disk would ask for the user input before the installation, then creates an answer file of the details inputted and then starts the installation, I want to try such a task and similar other things. Can I learn it easily?
Re: User inputs in Batch (.bat) files
Sometimes we need some user interaction in our batch files. We may need to know to which directory a file is to be copied, for example.
Or which drive needs to be formated.
There are many ways to achieve this user interaction.
The most basic form of user interaction, of course, is the PAUSE command, which halts the batch file until the user presses "any key" (apart from Ctrl, Alt, Shift, CapsLock, NumLock or ScrollLock).
Maybe not really sophisticated, but it works and is always available, in all DOS, Windows and OS/2 versions.
Re: User inputs in Batch (.bat) files
If you want the user to choose one of three options, you make a simple menu, then make three batch files whose names correspond to the menu choices:
Code:
@echo off
echo Please pick a number and hit Enter:
echo 1 - John
echo 2 - Ron
echo 3 - Shawn
After the above batch file runs, the user is dropped back to a DOS prompt. All you'd have to do is create three more batch files ( 1.bat, 2.bat, and 3.bat ) which would launch the appropriate programs.
Re: User inputs in Batch (.bat) files
Batch is usually used for computing without user interaction. All data are in files|DB|cmd line. Here is an example:
Create the following script and call it clientdir.cmd:
Code:
C:
CD \Clients
SET /P cname=[Enter Last Name]
MKDIR %cname%
CD %cname%
MKDIR subdir1
MKDIR subdir2
You can set up a shortcut to clientdir.cmd. Enjoy!