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