Jump to content

autoit equivalent to %1 type variables


Recommended Posts

With Batch files you can use %1, %2, etc... type variable to be almost like command line switches or undefined variables that are inputted by the user. For example-

@ECHO OFF

ECHO First Parameter is %1

ECHO Second Parameter is %2

ECHO Third Parameter is %3

If you named this bat file JOE and placed it in the c: drive than from the command prompt you could do the following:

JOE.bat open the door

Which would give you

First Parameter is open

Second Parameter is the

Third Parameter is door

This type of variable can be used in many ways, but 1 type of use is as kind of command line switches.

I'm wondering if there is a way to do this with AutoIt .exe files, so that you can get something like command line switches too.

QUESTIONS (after all that)

Is there a way to get???

"Autoit".exe open the door

First Parameter is open

Second Parameter is the

Third Parameter is door

What are various ways to get user input for "undefined" variables that the script will act upon?

Edited by autoitNOW
An ADVOCATE for AutoIT
Link to comment
Share on other sites

Well yes I could always just use a .bat/.cmd file or run cmd, but then what is the point of AutoIt? I'm interested in using only AutoIt to deal with such a problem.

EDIT: Ooooopsssss... I looked at $cmdline and running "scripts" but I still have issue with that.....

Edited by autoitNOW
An ADVOCATE for AutoIT
Link to comment
Share on other sites

Look up "Running Scripts" in the help file.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

Well yes I could always just use a .bat/.cmd file or run cmd, but then what is the point of AutoIt?  I'm interested in using only AutoIt to deal with such a problem.

Larry means that the %1 %2 stuff is passed to AutoIt and is available from the global array $CmdLine.
Link to comment
Share on other sites

I tried this but got errors ?

someone show me how this is done .

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] = 2

$CmdLine[1] = "param1"

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

@ScriptName = "myscript.au3"
Link to comment
Share on other sites

I tried this but got errors ?

You are trying to assign a value to an AutoIt macro; you cannot do that. Macros are read only.

Minor edit

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

I'm confused by this also.

In the batch file you go "joe.bat this that these", so then "this that these" is passed to the bat file's %1 %2 %3 variables. The batch file does not need to call another script and the user defines the variables at the command line.

This method ($cmdline) looks like I would include another script to run in addition to autoit but I'm not clear how this would allow for running an autoit compiled exe as if it had cmd line switches or allowing for "undefined" variables that come from user input .

Could somebody please give a functioning example script?

Is the nearest that AutoIt can get to this is the Inputbox command or GUI methods? Or are there various other ways to get this type of functionality?

Thanks again in advance.

An ADVOCATE for AutoIT
Link to comment
Share on other sites

autoitNOW, these two examples are the same:

myscript.au3 param1 "this is another param"

myscript.exe param1 "this is another param"

The first one calls AutoIt3.exe and runs the script with the parameters. You don't have to put AutoIt3.exe before the script name. Windows does it for you.

The second example does the same, suposing myscript.exe is the compiled script myscript.au3. In this case, there's no need to call AutoIt3.exe.

Link to comment
Share on other sites

This method ($cmdline) looks like I would include another script to run in addition to autoit but I'm not clear how this would allow for running an autoit compiled exe as if it had cmd line switches or allowing for "undefined" variables that come from user input .

Just test the $CmdLine array at the start of the script, and act accordingly. You can test for how many arguments were given at the command line, and ask the user to input (via some user interactin such as input box, etc) any invalid or not included command line switches.

This variable has nothing to do wtih another script... it's set on every script, and is an array that contains the number, and each of the command line elements passed.

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

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...