Jump to content

how to allow my script to accept switches?


kor
 Share

Recommended Posts

I'm not sure how to accomplish this or even what commands I should be looking at. I am wanting to pass switches to my script when executing it, and have my script interrupt those switches and do different things depending on what the switches are.

IE:

script.exe /e

How do I tell the script to accept that /e, and how do I get the script to use that /e to do something?

Basically what I want is that switch to be a drive letter, so if the switch is /e, then it would be Drive E:, but if the switch is /F, then it would be drive F:

Link to comment
Share on other sites

My code:

Global $drive = ""

ReadParameters()

MsgBox(0, "Drive is", $drive)

Func ReadParameters()
    For $i = 1 to $CmdLine[0]
        Select
            Case $CmdLine[$i] = "/d"
                If $i == $CmdLine[0] Then Error()
                If StringLeft($cmdline[$i+1], 1) == "/" Then
                    Error()
                Else
                    $drive = StringStripWS($CmdLine[$i + 1], 3)
                EndIf
        EndSelect
    Next
        If $drive == "" Then
            Error()
        EndIf
EndFunc

Func Error()
    MsgBox(0, "Error", "Invalid Parameters")
    Exit
EndFunc

Simplified from: http://motersho.com/blog/index.php/2009/10/20/autoit-command-line-parameters-a-new-approach/

Edited by kor
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...