Batch Script pass parameters

Diane Lonergan
Diane Lonergan used Ask the Experts™
on
I need to pass two parameters to a batch script at execution. Could someone please advise of the syntax. Fields I need to pass

Folder String : This will be a folder name e.g.  c:\MyFolder

File String: This will be a filename e.g. Myfile.csv
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
Commented:
Batch file "myscript.bat":

@echo off
echo Parm1:%1
echo Parm2:%2

Open in new window


Command line invocation passing parms:

myscript c:\MyFolder Myfile.csv

Open in new window


»bp
Bill PrewTest your restores, not your backups...
Top Expert 2016
Commented:
And if you use quotes on the command line (required if they contain spaces), like:

myscript "c:\MyFolder" "Myfile.csv"

Open in new window

Then %1 and %2 will also have the quotes around the value.  You can remove those when referencing by using %~1 and %~2.


»bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial