Sign in to follow this  
Followers 0
Newbie2

Script parameters

9 posts in this topic

#1 ·  Posted (edited)

How can I execute a script with parameters that the script will be able to use while running? All this using $CmdLine

Can someone give me an example?

Edited by Newbie2

Share this post


Link to post
Share on other sites



from the helpfile:

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

$CmdLine[0]= 2

$CmdLine[1] = "param1"

$CmdLine[2] = "this is another param"

Script example from the CompileAU3.au3 script:

$V_ARG = "Valid Arguments are:" & @LF
$V_ARG = $V_ARG & "    /in  ScriptFile " & @LF
$V_ARG = $V_ARG & "    /out Targetfile " & @LF
$V_ARG = $V_ARG & "    /icon IconFile " & @LF
$V_ARG = $V_ARG & "    /pass passphrase " & @LF
$V_ARG = $V_ARG & "    /comp 0 to 4  (Lowest to Highest) " & @LF
For $X = 1 To $CMDLINE[0]
   $T_VAR = StringLower($CMDLINE[$X])
   Select
      Case $T_VAR = "/?" Or $T_VAR = "/help"
         MsgBox(1, "Compile Aut2EXE", "Compile an AutoIt3 Script." & @LF & "commandline argument: " & $T_VAR & @LF & $V_ARG)
         Exit
      Case $T_VAR = "/in"
         $X = $X + 1
         $SCRIPTFILE_IN = $CMDLINE[$X]
      Case $T_VAR = "/out"
         $X = $X + 1
         $SCRIPTFILE_OUT = $CMDLINE[$X]
      Case $T_VAR = "/icon"
         $X = $X + 1
         $INP_ICON = $CMDLINE[$X]
      Case $T_VAR = "/pass"
         $X = $X + 1
         $INP_PASSPHRASE = $CMDLINE[$X]
         $INP_PASSPHRASE2 = $CMDLINE[$X]
      Case $T_VAR = "/compress" or $T_VAR = "/comp"
         $X = $X + 1
         $INP_COMPRESSION = Number($CMDLINE[$X])
         If $INP_COMPRESSION < 0 Or $INP_COMPRESSION > 4 Then $INP_COMPRESSION = ""
      Case $T_VAR = "/nodecompile"
         $INP_ALLOW_DECOMPILE = 0
      Case Else
         MsgBox(1, "Compile Aut2EXE", "Wrong commandline argument: " & $T_VAR & @LF & $V_ARG)
         Exit
   EndSelect
Next

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

10x, JdeB for your good will, but... do you have an easier sample? It's too complicated for a newbie like me... :D

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Its not that difficult...

Here's a basic one.... create the below script and compile it...

Msgbox(0,'param1',cmdline[1])

Msgbox(0,'param2',cmdline[2])

Then run it from the commandprompt:

yourscript.exe param1 param2

ok ? :D

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

OK, now!

10x :D

Share this post


Link to post
Share on other sites

Hi Newbie2,

:D

I don't get it. I have copied the 2 lines, compiled the script and nothing works!

WHYYYYYYYYYYYY?

:iamstupid:

Share this post


Link to post
Share on other sites

Maybe because you didn't actually pass the script 2 parameters?

Share this post


Link to post
Share on other sites

Shouldn't it be

Msgbox(0,'param1',$cmdline[1])
Msgbox(0,'param2',$cmdline[2])
With the $ sign?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

yes it should be with the $ .... :D

I just typed it online since he asked for a simple example....

You also ofcource need to make sure that 2 parameters are passed or else you get an error...

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          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  
Followers 0