Computing.Net > Forums > Disk Operating System > pass a arg to a batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

pass a arg to a batch file

Reply to Message Icon

Name: Chris
Date: April 16, 2001 at 11:27:04 Pacific
Comment:

Is there a way to pass an argument from the dos prompt to a batch file. I'm wanting to do the following:

test.bat ARGUMENT

What do I need in the batch file to pick this up? Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: Chris Hodapp
Date: April 16, 2001 at 18:32:56 Pacific
Reply:

There's an easy way to do this.
Inside the batch file, DOS will automatically substitute %1, %2, %3, %4, %5, %6, %7, %8, and %9 with whatever was in ARGUMENT. It separates it into 1, 2, etc. by spaces, so if you did TEST.BAT A 3 BLAH, then %1 would be substituted with A, %2 would be 3, and %3 would be BLAH.

Just put %1, %2, etc. just about anywhere in the batch file, just the way you see it - not in quotes or parentheses or anything, and the variables will be substituted.
Hope I helped...
-Chris


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: pass a arg to a batch file

Is there any ways to declare a variable inside a batch file ?? www.computing.net/answers/dos/is-there-any-ways-to-declare-a-variable-inside-a-batch-file-/3377.html

creating a batch file to rename fil www.computing.net/answers/dos/creating-a-batch-file-to-rename-fil/15089.html

checking a file date to execute a batch file www.computing.net/answers/dos/checking-a-file-date-to-execute-a-batch-file/1909.html