- Batch Script Tutorial
- Batch Script - Home
- Batch Script - Overview
- Batch Script - Environment
- Batch Script - Commands
- Batch Script - Files
- Batch Script - Syntax
- Batch Script - Variables
- Batch Script - Comments
- Batch Script - Strings
- Batch Script - Arrays
- Batch Script - Decision Making
- Batch Script - Operators
- Batch Script - DATE & TIME
- Batch Script - Input / Output
- Batch Script - Return Code
- Batch Script - Functions
- Batch Script - Process
- Batch Script - Aliases
- Batch Script - Devices
- Batch Script - Registry
- Batch Script - Network
- Batch Script - Printing
- Batch Script - Debugging
- Batch Script - Logging
- Batch Script Resources
- Batch Script - Quick Guide
- Batch Script - Useful Resources
- Batch Script - Discussion
Batch Script - Files Inputs
When a batch file is run, it gives you the option to pass in command line parameters which can then be read within the program for further processing. The batch files parameters can be recalled from within the program using the % operator along with the numeric position of the parameter. Following is how the command line parameters are defined.
- %0 is the program name as it was called.
- %1 is the first command line parameter.
- %2 is the second command line parameter.
- So on till %9.
Let’s take a look at a simple example of how command line parameters can be used.
Example
@echo off echo The first parameter is %1 echo The second parameter is %2 echo The third parameter is %3
Output
If the above code is stored in a file called test.bat and the file is run as
test.bat 5 10 15
then, following will be the output.
The first parameter is 5 The second parameter is 10 The third parameter is 15
batch_script_functions.htm
Advertisements