Jump to content



Photo

Launch a child AutoIt Script


  • Please log in to reply
11 replies to this topic

#1 Yusuke

Yusuke

    Seeker

  • Active Members
  • 11 posts

Posted 20 August 2007 - 09:35 AM

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.





#2 Tiger

Tiger

    Polymath

  • Active Members
  • PipPipPipPip
  • 220 posts

Posted 20 August 2007 - 09:44 AM

ShellExecute and then you can write in the another script "$CMDLINE"
My UDFs:- _RegEnumKeyPosted Image

#3 Yusuke

Yusuke

    Seeker

  • Active Members
  • 11 posts

Posted 20 August 2007 - 10:06 AM

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.

#4 James

James

    jbrooksuk

  • MVPs
  • 9,468 posts

Posted 20 August 2007 - 10:11 AM

Add a function with another GUI in it.

#5 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 20 August 2007 - 11:55 AM

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

#6 Tiger

Tiger

    Polymath

  • Active Members
  • PipPipPipPip
  • 220 posts

Posted 20 August 2007 - 12:36 PM

Also you have an main script and achild script.

run main script
main script run child script

is it so ok
My UDFs:- _RegEnumKeyPosted Image

#7 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 20 August 2007 - 03:14 PM

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, 20 August 2007 - 05:23 PM.

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

#8 Tiger

Tiger

    Polymath

  • Active Members
  • PipPipPipPip
  • 220 posts

Posted 20 August 2007 - 04:49 PM

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:- _RegEnumKeyPosted Image

#9 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 20 August 2007 - 05:20 PM

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

#10 piccaso

piccaso

    Rock me, Amadeus!

  • MVPs
  • 893 posts

Posted 20 August 2007 - 05:46 PM

check out CoProc (from my signature) it might be what you want.
Posted Image CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

#11 Yusuke

Yusuke

    Seeker

  • Active Members
  • 11 posts

Posted 21 August 2007 - 05:17 PM

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 ?

#12 piccaso

piccaso

    Rock me, Amadeus!

  • MVPs
  • 893 posts

Posted 21 August 2007 - 07:57 PM

We convinced Jon to remove this limitation but it never happened...
Posted Image CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users