Jump to content

Launch a child AutoIt Script


 Share

Recommended Posts

Hi,

Is there a way to launch an AutoIt script from another AutoIt script but that the child script can access the variables of the parent script ?

Basically, I'm looking for something similar to the CALL command in batch scripting.

VBScript also had something similar with ExecuteGlobal and I was happy with it, but I'm looking to completely switch to AutoIt now.

Execute isn't what I want since it severely limits the usefulness of the child scripts.

Environment, Files, Dir, Disk, GUI, InputBox, MsgBox, Misc, Network, Obj/COM, Process, Registry, Tray, WinKill functions implying deletion or modification will not be executed. They will set @error to 9999 and return "".

Thanks a lot in advance.

Link to comment
Share on other sites

ShellExecute and then you can write in the another script "$CMDLINE"

Thanks, but sorry, it is not exactly what I want : I know how to run another script, but what I would like to know if it is possible to to launch a child script and that this script can access the variables and functions of the parent script.

Link to comment
Share on other sites

Thanks, but sorry, it is not exactly what I want : I know how to run another script, but what I would like to know if it is possible to to launch a child script and that this script can access the variables and functions of the parent script.

No. And BTW, that doesn't work with CALL in Windows shell scripting either. CALL spawns a separate shell with it's own copy of the environment. Any changes made generally only exist within that shell (SETX provides a way to change external environment variables), and are destroyed when you exit that shell.

There are many ways to pass data between scripts, but not for directly reading the variables in another process.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I created a demo a while back, specifically to demonstrate two AutoIt scripts communicating with each other by way of controls in each other's GUIs: Using GUI Controls for interprocess comms

Hope that helps...

:)

Zedna pointed out another great method (if you're into DLLs) using the WM_COPYDATA windows message: SendMessage Datastructure (reply by martin)

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I write a small script.

Script: Main

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.4.9
 Author:         Tiger

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

MsgBox(64 + 8192, "", "Main-Script ist running")

If MsgBox(32 + 4 + 8192, "", "Would you start the child-script?") = 6 Then
    
    ShellExecute(@AutoItExe, @ScriptDir & "\Child.au3 run")
    
Else
    
    Exit
    
EndIf
My UDFs:- _RegEnumKey
Link to comment
Share on other sites

I write a small script.

That works to get the first script to run a second script, but does not do any communication between them. The first script will exit as soon as it launches the second, so they won't even be running together at the same time.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks everyone.

To explain a bit more what I wanted to do, I have a main GUI in a script that runs other scripts in subdirectories (the main script looks for *.au3 and launch them) and I wanted these child script to communicate with the GUI, and mostly an embedded IE Control.

I have seen _IEAttach which allows me to get the object of the IE in my main window, so that's not too bad and will use that for now.

It is a pity though that the Execute function is so limited.... VBScript's ExecuteGlobal was great for that. It is really handy to be able to access all the variables from the parent script from a child script without setting up WM_COPYDATA or TCP client/server.

Just out of curiousity, anybody knows the reason for the Execute function to be so limited ? Security, I guess ?

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