Sign in to follow this  
Followers 0
MentalPower

Getting Parameters from the Commandline

4 posts in this topic

My question is rather simple. Say I call my compiled script like "C:\MyScript.exe param1 param2 param3", how do I get the "param1 param2 param3" part from within my script. Basically I want my script to restart a program when called without params, but to only close it when called with some parameter.

Thanks

Share this post


Link to post
Share on other sites



My question is rather simple. Say I call my compiled script like "C:\MyScript.exe param1 param2 param3", how do I get the "param1 param2 param3" part from within my script. Basically I want my script to restart a program when called without params, but to only close it when called with some parameter.

Thanks

From the $CmdLine array -- per the help file under... wait for it... "Command Line Parameters"

Command Line Parameters

The special array $CmdLine is initialized with the command line parameters passed in to your AutoIt script. Note the scriptname is not classed as a parameter; get this information with @ScriptName instead. A parameter that contains spaces must be surrounded by "double quotes". Compiled scripts accept command line parameters in the same way.

$CmdLine[0] is number of parameters

$CmdLine[1] is param 1 (after the script name)

$CmdLine[2] is param 2 etc

...

$CmdLine[$CmdLine[0]] is one way to get the last parameter...

So if your script is run like this:

AutoIt3.exe myscript.au3 param1 "this is another param"

$CmdLine[0] equals... 2

$CmdLine[1] equals... param1

$CmdLine[2] equals... this is another param

@ScriptName equals... myscript.au3

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

From the $CmdLine array -- per the help file under... wait for it... "Command Line Parameters"

:)

Thanks, I just spent 2hrs looking for "passing parameters", "parameters", "reading parameters" and the like. KISS FTW. Thanks again.

Share this post


Link to post
Share on other sites

Thanks, i was looking for this for a long time..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0