Monday, October 31, 2016

Passing Command Line Parameters to a Autohotkey Script

Autohotkey is een scripting language designed for Test Automation. It is easy to use and the programs created are often very compact/light-weight. More info: http://ahkscript.org/

Between two or more scripts,  command line parameters may be passed among them, like this:







the '0' is the number of parameters!
(used in a if closure!)



the number of parameters, values of the 4 parameters

This script will be called by another script shown as below:






Run the script callPara.ahk (or callPara.exe) will show the following results:
- Starting ...
- got 4, a, b, c, 20000

If we call paraTest.exe %p1% %p2%, we will get the following answer:
- Starting ...
- needed at least 3 params, got 2

Please note: in a If closure, it must not contain ( ), otherwise it will not work:

if (0 < 3)  will always be true!

In the meantime, in a If closure with more conditions, the paramter must be at most left side:

line = blabla
if( line) and 0<3   ;will not work

if 0<3 and (line)   ;seems to work, but not reliable! (a bug?)

It is safe to use nested If closures:

if 0<3
    if(line)
        ;do something

Similarly, you may use '1', '2' or any other nubmer to replace '0',
if 1<3
    msgbox the first paramter is less than 3: %1%
if 2<3
    msgbox the second paramter is less than 3: %2%

When compared to a variable, like i = 3, then it must use %i% in the If closure,

i=3
if 3<%i%
    msgbox the third paramter is less than %i%: %3%

More info: See Passing Command Line Parameters to a Script 

No comments:

Post a Comment