Jump to content

Running Au3 Script With External Parameters

Recommended Posts


I am writing a script ATM so that I can mount images into daemon tools automatically and run an application (i.e. the game that is associated with the mounted image.) I have also given the script the ability to read from an INI file, to find the location of the mounted image and which executable to run etc.

My problem is specifying which INI file to read from an external parameter/switch.

For Example

"c:\Program Files\image mounter\my script.au3" -Quake4

So this would read the Quake4 INI file and feed the variables into the script that way.

Is there any way to do this?

Many Thanks

Link to post
Share on other sites

Copied from the help file: AutoIt > Using AutoIt > Running Scripts

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

In addition to $CmdLine there is a variable called $CmdLineRaw that contains the entire command line unsplit, so for the above example:

$CmdLineRaw equals... myscript.au3 param1 "this is another param"

Link to post
Share on other sites

Here is a quick sample, more effecient ways are avialible, this is just an example as too what you can do.

    Case $CmdLine[0] = 1
            Case $CmdLine[1] = "-e"
                MsgBox(0, "Parameter", $CmdLine[1] & " is correct")
            Case Else
                MsgBox(16, "Parameter", $CmdLine[1] & " is not correct.")
    Case Else
; Run Without Parameters
        MsgBox(0, "Parameter", "No Parameters")

AutoIt Smith

Edited by AutoIt Smith
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...