Jump to content
Sign in to follow this  
enko

Command Line?

Recommended Posts

enko

Was wondering if its possible to pass integers or variables through the command line, like:

Program.exe -name enko -pin 0001 -age 89 -sex male

then $name $pin $age & $sex would be those.

Is this possible, if so how?

Share this post


Link to post
Share on other sites
Guest rathore

its possible using the array $CMDLINE

$CMDLINE[0] stores the no. of parameters passed & $CMDLINE[1] & $CMDLINE[2] & so on store the parameter.

Share this post


Link to post
Share on other sites
enko

Program.exe -name enko -pin 0001 -age 89 -sex male

so $CMDLINE[0] would = 4, $CMDLINE[1] = enko, $CMDLINE[2] = 0001 and so on? what if like there isnt a $CMDLINE[4]?

Share this post


Link to post
Share on other sites
Helge

Correct !

what if like there isnt a $CMDLINE[4]?

What ?

Share this post


Link to post
Share on other sites
Jos

Nope....

$CMDLINE[0] = 8

$CMDLINE[1] = -name

$CMDLINE[2] = enko

$CMDLINE[3] = -pin

$CMDLINE[4] = 0001

this is an example script you could use to test for commandline parameters:

$BATCH = 0
$INSTALL=0
$NAME = ""
$ADDR = ""
$V_ARG = "Valid Arguments are:" & @LF & _
      "    /batch   - text to explain option." & @LF & _
      "    /install - text to explain option." & @LF & _
      "    /n NAME  - Name." & @LF & _
      "    /a Address - Address"  & @LF
For $X = 1 To $CMDLINE[0]
   $T_VAR = StringLower($CMDLINE[$X])
   Select
      Case $T_VAR = "/batch"
         $BATCH = 1
      Case $T_VAR = "/install"
         $INSTALL = 1
      Case $T_VAR = "/n"
         $X = $X + 1
         $NAME = $CMDLINE[$X]
      Case $T_VAR = "/a"
         $X = $X + 1
         $ADDR = $CMDLINE[$X]
      Case Else
         If $BATCH = 0 Then
            MsgBox( 1, "Error", "Wrong commandline argument: " & $T_VAR & @LF & $V_ARG,)
         EndIf
         Exit
   EndSelect
Next
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  

×