Jump to content

Recommended Posts

Posted

Hi

Is it possible to execute the following snippet using the Run() command with a syntax like this:

Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand)

where the $sCommand variable contains the statements stacked in a single line?
In the following test script I get an odd error.
Any advise is welcome.
Thanks

; Testing the /AutoIt3ExecuteLine parameter
;
; the following line works
Local $sMsg = "Hello", $Dummy = MsgBox(0, "Debug", $sMsg)
MsgBox(0, 0, "Pause")
;
; the following line doesn't instead. Why?
Local $sCommand = 'Local $sMsg = "Hello", $Dummy = MsgBox(0,"Debug", $sMsg)'
Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand)
MsgBox(0, 0, "Pause")

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

  • Developers
Posted

Try:

Local $sCommand = '"Local $sMsg = ""Hello"", $Dummy = MsgBox(0,""Debug"", $sMsg)"'
Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

:) that way it works.

I have a quite long $sCommand string I'm working on, I will try to use quotation marks as you showed here.

... Thank Mr. Jos

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

  • Developers
Posted

It is not too difficult just do the following: :)

Local $sCommand = 'Local $sMsg = "Hello", $Dummy = MsgBox(0,"Debug", $sMsg)'
$sCommand = Stringreplace($sCommand,'"', '""')
$sCommand = '"' & $sCommand & '"'
Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

interesting.

Local $sCommand = _
        'Local ' & _
        '$Dummy1 = MsgBox(0,"Debug", ""), ' & _
        '$Dummy2 = Sleep(500), ' & _
        '$Dummy3 = WinWaitActive("Debug",""), ' & _
        '$Dummy4 = ControlClick("Debug","","[CLASS:Button; TEXT:OK]"), ' & _
        '$Dummy5 = Sleep(3000), ' & _
        '$Dummy6 = MsgBox(0,"Debug2", "")'

$sCommand = '"' & StringReplace($sCommand, '"', '""') & '"'
ConsoleWrite($sCommand & @CRLF)
Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand)
MsgBox(0, '', 333)

This can be used for a workaround for some JavaScript Dialog box popuped with IE.au3 (was discused recently here on the forum)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

thanks @Jos for the tip, very comfortable indeed.
the line that I am trying to run is as follows

Local $sCommandLine = 'local $ObjShell = ObjCreate("Shell.Application"), $ObjShellWindows = $ObjShell.Windows(), $ObjIE = $ObjShellWindows.item(' & $aRefs[1] & '), $oDocument = $ObjIE.Document, $Dummy = Execute("$oDocument"' & $sMethod & ')'

But it causes to carsh AutoIt .... :blink: (running on AutoIt v. 3.3.14.2 Win7 x64)
Perhaps there is some subtle bug I have to find in my script ...
What I'm trying to do is to perform a click on a button of the browser completely from an external script (but the whole script should be in the $sCommandLine variable instead that in an external file).

Hi @mLipok, thanks for your answer,

in the snippet you posted, you are dealing with an MsgBox, and so there is no need to pass Objcts references to the external script, while what I'm trying to do is to pass reference of our Browser obj and reference of our Element Obj (the button) to the external script so that it (the external script) can have references to what it has to manage. (sending a click in this case)
Here is my script which I am experiencing. The crash occurs in _CallFromExternal() function.

  Reveal hidden contents

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

  • Developers
Posted (edited)

That's is not a run-able line for me as I am missing the variables. so can't really test as you also haven't defined what you mean with "crash".

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

@Chimp please change your example by using my "Syntax" concept of writing "code" for this "one liner" :

Local $sCommand = _
        'Local ' & _
        '$Dummy1 = MsgBox(0,"Debug", ""), ' & _
        '$Dummy2 = Sleep(500), ' & _
        '$Dummy3 = WinWaitActive("Debug",""), ' & _
        '$Dummy4 = ControlClick("Debug","","[CLASS:Button; TEXT:OK]"), ' & _
        '$Dummy5 = Sleep(3000), ' & _
        '$Dummy6 = MsgBox(0,"Debug2", "")'

$sCommand = '"' & StringReplace($sCommand, '"', '""') & '"'

This way is much easier to read.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

sorry for the messy code
here is the _CallFromExternal() function with some comments

Func _CallFromExternal(ByRef $aRefs)
    ; idea from here:
    ; https://www.autoitscript.com/forum/topic/11823-attaching-to-an-existing-ie-instance-one-method/#comment-81693
    ; ----- expanded form -----
    ; in input we have references to the objects in this array:
    ;
    ;            $aRefs[0] = $hoIE                  ; HWND of the passed browser
    ;            $aRefs[1] = $item                  ; item nr, of the browser Obj within the Shell.Application.Windows collection
    ;            $aRefs[2] = _GetPathTo($oElement)  ; xPath of the Element we need to manage within the browser
    ;
    ; 1) Instantiate the shell obj
    ; Local $ObjShell = ObjCreate("Shell.Application")
    ;
    ; 2) get collection of all ShellWindows (IE and File Explorer)
    ; Local $ObjShellWindows = $ObjShell.Windows()
    ;
    ; 3) Point to the targhet browser using the received item nr.
    ;    something like _IEAttach() ....
    ;    so we retrieve an Obj
    ; Local $ObjIE = $ObjShellWindows.item($aRefs[1])
    ;
    ; 4) Check if obtained obj has the same HWND of our targhet browser (it should)
    ;  .... to do
    ;
    ; 5) Point to the .Document obj
    ; Local $oDocument = $ObjIE.Document
    ;
    ; 6)  Construct the method from the given xPath
    ;     xPath for example is something like this:
    ;     /HTML[0]/BODY[0]/BUTTON[0]
    ;     and afther the StringReplaces we have something like this:
    ;     .getElementsByTagname("HTML").item(0).getElementsByTagname("BODY").item(0).getElementsByTagname("BUTTON").item(0).click()
    ;
    ; Local $sMethod = StringReplace(StringReplace(StringReplace($aRefs[2], '/', '.getElementsByTagname("'), '[', '").item('), ']', ')') & ".click()"
    ;
    ; 7) call the wanted method ageinst the element
    ; $Dummy = Execute("$oDocument" & $sMethod)
    ; ------------------------------------------------------------------------------
    ; the complete list of above Commands stacked on a single line should be like this
    ; Local $ObjShell = ObjCreate("Shell.Application"), $ObjShellWindows = $ObjShell.Windows(), $ObjIE = $ObjShellWindows.item($aRefs[1]), $oDocument = $ObjIE.Document, $Dummy = Execute("$oDocument" & $sMethod)
    ; replacing the $aRefs[*] and the $sMethod with it's values whe should has
    Local $sMethod = StringReplace(StringReplace(StringReplace($aRefs[2], '/', '.getElementsByTagname("'), '[', '").item('), ']', ')') & ".click()"
    Local $sCommandLine = 'local $ObjShell = ObjCreate("Shell.Application"), $ObjShellWindows = $ObjShell.Windows(), $ObjIE = $ObjShellWindows.item(' & $aRefs[1] & '), $oDocument = $ObjIE.Document, $Dummy = Execute("$oDocument"' & $sMethod & ')'
    $sCommandLine = StringReplace($sCommandLine, '"', '""')
    $sCommandLine = '"' & $sCommandLine & '"'
    ; and now we can run it from 'external' ...??  maybe...
    ; MsgBox(0, "Debug", $sCommandLine)
    Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommandLine)
    MsgBox(0, "Debug: CommadLine", $sCommandLine) ; this is the resulting Command Line
EndFunc   ;==>_CallFromExternal

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted
  On 3/25/2016 at 11:52 AM, Jos said:

That's is not a run-able line for me as I am missing the variables. so can't really test as you also haven't defined what you mean with "crash".

Jos

Expand  

The script from Post #6 (within spoiler) is runnable and I get an "APPCRASH" window running it:

2lcurex.jpg

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted

just for the record
the APPCRASH was caused by the presence of the Execute() statement within the $sCommandLine string.
by replacing this part   $Dummy = Execute("$oDocument"' & $sMethod & ')'
with this part   $Dummy = $oDocument' & $sMethod  solved the problem.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted
  On 3/25/2016 at 11:15 AM, mLipok said:

This can be used for a workaround for some JavaScript Dialog box popuped with IE.au3 (was discused recently here on the forum)

Expand  

Here is example how this can be used with IE.au3 :

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...