Sign in to follow this  
Followers 0

AutoIt3ExecuteScript question

5 posts in this topic

Posted (edited)

This will execute some script.

Is there any way to use this feature to execute script that is not on HD but stored in memory (variable)?

...or pass more than one line of code before executing?

Edited by trancexx

Share this post


Link to post
Share on other sites



Posted

The answer is in your question i think :)

Use Execute()...

$sReadIncl = StringFormat('TestFunc("%s")\nMsgBox(36, "", "Are you sure?")', "Test")
_ExecuteCode($sReadIncl)

Func _ExecuteCode($sCode)
    $aExecuteCode = StringSplit(StringStripCR($sCode), @LF)
    
    For $i = 1 To $aExecuteCode[0]
        If $aExecuteCode[$i] <> "" Then ConsoleWrite(Execute($aExecuteCode[$i]) & @LF)
    Next
EndFunc

Func TestFunc($sParam)
    Return $sParam ;Will return "Test" to the console (by _ExecuteCode function)
EndFunc

Share this post


Link to post
Share on other sites

Posted (edited)

Or you can write the code to the temporary file:

#include <File.au3>

$sCode = _
    '#NoTrayIcon' & @CRLF & _
    'ConsoleWrite("Return from Line #" & @ScriptLineNumber & ": " & TestFunc("Test"))' & @CRLF & _
    'ConsoleWrite("Return from Line #" & @ScriptLineNumber & ": " & MsgBox(36, "", "Are you sure?"))' & @CRLF & _
    'Func TestFunc($sParam)' & @CRLF & _
    '   Return $sParam' & @CRLF & _
    'EndFunc'

$sRet = _AutoIt3ExecuteCode($sCode)

ConsoleWrite($sRet)

Func _AutoIt3ExecuteCode($sCode)
    Local $sTmpFile = _TempFile(@TempDir, "~AutoIt3ExecuteCode_")
    FileWrite($sTmpFile, $sCode)
    
    Local $iPID = Run(@AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteScript "' & $sTmpFile & '"', @WorkingDir, 0, 2)
    Local $sStdOut_Read = "", $sStdOut_Ret = ""
    
    While 1
        $sStdOut_Read = StdoutRead($iPID)
        If @error <> 0 Then ExitLoop
        
        If $sStdOut_Read <> "" Then $sStdOut_Ret &= $sStdOut_Read & @CRLF
        
        Sleep(10)
    WEnd
    
    FileDelete($sTmpFile)
    
    Return $sStdOut_Ret
EndFunc
Edited by MrCreatoR

Share this post


Link to post
Share on other sites

Posted

This will execute some script.

Is there any way to use this feature to execute script that is not on HD but stored in memory (variable)?

...or pass more than one line of code before executing?

That would be ideal wouldn't it... the answer to your specific question is no.

Share this post


Link to post
Share on other sites

Posted

That would be ideal wouldn't it...

And more.

@MrCreatoR; about this second method...

Yes, we are thinking the same, but again, problem is usage of HD. One who finds the solution for this will be new Autoit's hero, I think.

Nevertheless, this opens new possibility. I will post in 'Example Scripts' section.

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  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.