Jump to content
Sign in to follow this  
magician13134

$CmdLine

Recommended Posts

magician13134

Ok, I just saw this in a couple scripts... and it confuses me. Not to much is returned on a forum search, and it's not in the help file.

So, as far as I can figure, it returns parameters of program as executed by Windows...?

But:

How do I use it?

Why doesn't it have to be declared?

It seems more like one of those terms starting with '@' than '$'...

Anyone up to giving me a brief explanation?

Share this post


Link to post
Share on other sites
weaponx

$CmdLine[0] Returns number of params

$CmdLine[1] 1st param

$CmdLine[2] 2nd param

Share this post


Link to post
Share on other sites
Buey

In a DOS prompt, when you type:

C:> myprogram.exe 5 2

The 5 and 2 are command line parameters of the program. When your AutoIt script is run, anything passed to it in that fashion will be automatically put into a predefined array $CmdLine, where $CmdLine[0] is the number of arguments that were passed, and $CmdLine[1]... are the actual parameters.

So, when running:

C:> myautoitprogram.exe hello test

$CmdLine[0] = 2

$CmdLine[1] = "hello"

$CmdLine[2] = "test"

As to why it's not a macro (@), my guess would be because it's an array. I don't think there are any array macros, so it was set as a variable. You can treat it as a ubiquitous macro though, it gets declared and set when the program starts.

Edited by Buey

Share this post


Link to post
Share on other sites
flyingboz

If you need the entire command line, use $cmdlineRaw

Note that you will have to properly parse the arguments yourself....


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

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  

×