Jump to content

running an autoit exe from qtp with parameters


Go to solution Solved by MHz,

Recommended Posts

using the help I can call this script(see below) : like this from QTP (Quick test professional - automation tool)

Set oAutoIt = CreateObject("AutoItX3.Control")
oAutoIt.Run("C:PWCOnlineQTPtraytip.exe")

 
Call ("traytipme, "This is a title", "This is a message")




Func traytipme($param1, $param2)
   TrayTip($param1 & @CRLF  , $param2, 5, 1)
Sleep(5000)
EndFunc
 
but what I want to do is call it with parameters so that the autoit script (which needs changing and I don 't know how to do this) so I can send the values that i want to correspond to "This is a title", "This is a message"
 
 
I'll also need to change my Run statement to have 2 paramaters - I guess it will be oAutoIt.Run("C:PWCOnlineQTPtraytip.exe ""This is a TITLE"" ""This is a message"")
 
But I'm not sure 
 
can anyone help me?
 
Thanks
Joe
 
 
 
Link to comment
Share on other sites

AutoIt easily supports command line parameters - search CmdLine in the help.

as for the QTP syntax - you'll have to consult QTP help or forum.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • Moderators

joeloyzaga,

AutoIt has an internal array $CmdLine which always exists so there is never a problem accessing it. The [0] element holds the number of command line parameters used to call the script - it will be set to 0 if there were none. To access the parameters just loop through the $CmdLine array from 1 to the value in the [0] element. :)

Clear enough?

M23

P.S. This is the rewrite in the current Beta Help file:

Command Line Parameters

Passing command line parameters to your own executable is achievable in AutoIt. Passed commandline parameters can be viewed by using the constant variables $CmdLine and $CmdLineRaw. Assigning these variables with new data will cause AutoIt to return an error, as these cannot be changed during the script's execution. Note that both variables exist whether commandline parameters are passed or not.

The special array $CmdLine is initialized at the start of the script with the command line parameters passed to your AutoIt script. If running your script instead of the executable, then the ScriptName.au3 willl be ignored as a parameter.

If you're passing strings with spaces, then you will need to escape these using "double quotes" in your commandline string.

$CmdLine[0] ; Contains the total number of items in the array.
$CmdLine[1] ; The first parameter.
$CmdLine[2] ; The second parameter.
...
$CmdLine[nth] ; The nth parameter e.g. 10 if the array contains 10 items.
So if you were to run your script directly using AutoIt3.exe:

AutoIt3.exe myScript.au3 param1 "This is a string parameter" 99
$CmdLine[0] ; This contains 3 parameters.
$CmdLine[1] ; This contains param1 and not myScript.au3 as this is ignored when running non-compiled.
$CmdLine[2] ; This contains This is a string parameter.
$CmdLine[3] ; This contains 99.
$CmdLineRaw ; This contains myScript.au3 param1 "This is a string parameter" 99.
So if you were to use the compiled executable by passing commandline parameters:

myProg.exe param1 "This is a string parameter" 99
$CmdLine[0] ; This contains 3 parameters.
$CmdLine[1] ; This contains param1.
$CmdLine[2] ; This contains This is a string parameter.
$CmdLine[3] ; This contains 99.
Note: A maximum of 63 parameters can be returned by the array $CmdLine[]. If you would like to see the entire commandline string passed to an AutoIt executable, then use $CmdLineRaw for the entire parameter string.

#include <WinAPIShPath.au3>
#include <Array.au3>

; An alternative to the limitation of $CmdLine[] only being able to return a maximum of 63 parameters.

Local $aCmdLine = _WinAPI_CommandLineToArgv($CmdLineRaw)
_ArrayDisplay($aCmdLine)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

to make use in your case of what Melba23 clearly explained,
try to compile this simple script

If @Compiled Then
    If $CmdLine[0] = 2 Then ; are 2 parameters passed to the executable?
        TrayTip($CmdLine[1], $CmdLine[2], 5, 1)
        Sleep(5000)
    Else
        MsgBox(0, "debug", "wrong nr. of parameters")
    EndIf
Else
    MsgBox(0, "debug", "scripr must be compiled")
EndIf

then execute it from a dos prompt passing 2 parameters
example: script.exe Hello Welcome
a tooltip should appear with the 2 parameters displayed

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Why do you want to use QTP in combination with AutoIT?

Both tools are in many ways comparable (QTP has a nicer UI and IDE compared to AutoiIT)

But I feel regarding recognizing objects AutoIT comes close to QTP

With some additional UDF like

'?do=embed' frameborder='0' data-embedContent>>

'?do=embed' frameborder='0' data-embedContent>>

'?do=embed' frameborder='0' data-embedContent>>

and IE.UDF

You can do the same things as in QTP

Link to comment
Share on other sites

  • Moderators

joeloyzaga,

I do not use AutoItX so this is a complete WAG. :wacko:

From QTP:

oAutoIt.Run("C:\PWCOnlineQTP\traytip.exe param1 param2")
Then in AutoIt

; Check there are the correct number of parameters
If $CmdLine[0] = 2 Then
    ; No need to use "Call" - just name the function and pass the parameters
    traytipme($CmdLine[1], $CmdLine[2])
EndIf

Func traytipme($param1, $param2)
    TrayTip($param1 & @CRLF, $param2, 5, 1)
    Sleep(5000)
EndFunc
Try that and see if it works. :)

M23

P.S. WAG - Wild Ass Guess! ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Solution

I'll also need to change my Run statement to have 2 paramaters - I guess it will be oAutoIt.Run("C:PWCOnlineQTPtraytip.exe ""This is a TITLE"" ""This is a message"")

So this is VBS in QTP? If so then double up the double quotes and use braces only if you retrieve the return value. Try this line

oAutoIt.Run """C:\PWCOnlineQTP\traytip.exe"" ""This is a TITLE"" ""This is a message"""

:)

Link to comment
Share on other sites

  • 3 years later...

Hi,

In continuation with this script. I have the following problem

Desperately looking for a solution here. I have the following script in UFT which is working fine. However I want to substitute this hard coded parameter by variables  rpdate & date. I have tried with lot of options here. but not able to call the autoit exe file.

Dim rpdate
Dim LegalEntity
LegalEntity = 36004367

rpdate = "28-02-2017"
'Legal_entity_Id = "36000586"
path = "H:\Sprint\Automation\Corepautomate.exe"

Set oAutoIt = CreateObject("AutoItX3.Control")

oAutoIt.Run("H:\Sprint\Automation\Corepautomate.exe 28-02-2017 36004367")

The autoit script is which is also working fine.

 

If $CmdLine[0] = 2 Then
    ; No need to use "Call" - just name the function and pass the parameters
    corep_reports($CmdLine[1], $CmdLine[2])
EndIf

 

Func corep_reports($rpdate, $legalentity)

------------------------------

-------------------------
EndFunc

 

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