Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
Doc Symbiosis

Howto pass a parameter to AutoIT?

Recommended Posts


$CmdLine

you have to make the instructions in the script itself

ie: if $CmdLine[1] = "/?" then msgbox("help")

and the variable i are separated by spaces

ie: autoittest.exe log user

this would make $CmdLine[1] = "log"

and $CmdLine[2] = "user"

search the manual im sure theres some help there.

Share this post


Link to post
Share on other sites

A simple example

If $CMDLINE[0] = 2 Then
$vanilla = $CMDLINE[1]
$chocolate = $CMDLINE[2]
MsgBox(0x40000, 'CMDLINE', $vanilla & @CRLF & $chocolate)
EndIf

Share this post


Link to post
Share on other sites
If $CMDLINE[0] And $CMDLINE[1] = '/?' Then
MsgBox(0x40000, 'Help', 'Not a problem;)')
Exit
EndIf

Share this post


Link to post
Share on other sites

I've written an AutoIt script to make Nero portable. It works great, except for one problem. I need to have the script (compiled of course) pass a single parameter (/w) to the Nero executable via shortcut. This will allow me to select Nero Express without having to go through Nero's main interface, or if I use a shortcut for Nero.exe, it loads the main interface.

I've spent literally hours searching the AutoIt forum and help file, google and here without results. There is not one clear explanation of how to pass a parameter easily.

Here's the line that runs Nero.

RunWait(@ScriptDir & "\Nero\Nero.exe")

It should be as simple as adding $1 or %1 like this (like every other language on the planet):

RunWait(@ScriptDir & "\Nero\Nero.exe" & $1)

But of course that doesn't work. The genius that wrote AutoIt removed that nice feature from the latest version.

I don't understand $CmdLine at all. It makes no sense.

Share this post


Link to post
Share on other sites
It should be as simple as adding $1 or %1 like this (like every other language on the planet)

(.../...)

I don't understand $CmdLine at all. It makes no sense.

:wacko:

$CmdLine[0] lets you test the number or space-delimited arguments

$CmdLine (where i is an integer lower or equal to $CmdLine[0]) returns you the i-th argument.

In other words : your $1 or %1 becomes $CmdLine[1] :rolleyes:

Thus, your script becomes (this is a very bad-written sample) :

If Not $CmdLine[0] Then
RunWait(@ScriptDir & "\Nero\Nero.exe")
Else
RunWait(@ScriptDir & "\Nero\Nero.exe" & " " & $CmdLine[1])
EndIf

As you can see, the genius who wrote $CmdLine thing forces you to write error-trapping code...

++

Share this post


Link to post
Share on other sites

Thank you very much, Delprat. It may be badly coded but it works great. It's also the best explanation I've seen yet.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×