Jump to content

Communication between 2 scripts


Recommended Posts


I would like to send an array from a script to a another. This array has 1000 rows and 4 columns with this kind of data :

1st row  =     528  ;  31  ;   HOSTNAME|1|02:45:47|abcdefgh|username|5   ;   old

2nd row = ...

What IPC should I use ?



Link to comment
Share on other sites

I think it could be a situation of parent - child communication between 2 processes (compiled scripts).

with the use of consoleread / consolewrite and stdin / stdout

we will need more info to help you out

Edited by Nine
Link to comment
Share on other sites



It's not perfect real time but should work in most cases.


Toss in some file handling and file cleanup to keep things working properly. 


Or go the extra mile and use a database.

Link to comment
Share on other sites

34 minutes ago, ViciousXUSMC said:

It's not perfect real time but should work in most cases.

But if you need real time, you could use @ViciousXUSMC idea combine with a simple protocol using my approach of parent-child inter-process communication. 

Link to comment
Share on other sites

Link to comment
Share on other sites

Hi tatane :)

Here are 2 scripts showing how to pass a 2 Dimension Array from a script to another.
With the help of jguinch's ArrayMultiDim.au3, it's possible, here is the link of his work :


He's got a function that transposes the whole Array into a String, it's the String that will be passed as a Parameter from a script to the other. Then a 2nd function will transpose the String back to an Array, job done !

I attach at the end of this post jguinch's ArrayMultiDim.au3 but it's a good idea to read what he said about all the functions he created. After download, just place his file ArrayMultiDim.au3 in the same folder as the 2 scripts below, named "script part1.au3" and "script part2.au3"

; This is "script part1.au3"
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ArrayMultiDim.au3> ; Author jguinch

Local $aArray[3][4]
For $row = 0 to 2
    For $col = 0 to 3
        $aArray[$row][$col] = $row & ":" & $col

_ArrayDisplay($aArray, "in script 1 : Array", "", $ARRAYDISPLAY_COLALIGNCENTER)

Local $sStringFromArray = _ArrayToDeclarationString($aArray)
MsgBox($MB_TOPMOST, "in script 1 : String From Array", $sStringFromArray)

$iPID = Run(@AutoItExe & " /AutoIt3ExecuteScript " & chr(34) & @ScriptDir & "\script part2.au3" & chr(34) & _
    " " & $sStringFromArray)

If $iPID = 0 Then
   MsgBox($MB_TOPMOST, "Error", "'script part2' didn't lauch")
   MsgBox($MB_TOPMOST, "Back to script 1", "Great : this message shows only after 'script part2' has ended !")


; This is "script part2.au3"
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ArrayMultiDim.au3> ; Author : jguinch

$sParams = "$CmdLineRaw = " & $CmdLineRaw & @CRLF
For $i = 0 To $CmdLine[0]
   $sParams &= @CRLF & "$CmdLine[" & $i & "] = " & $CmdLine[$i] & @CRLF

MsgBox($MB_TOPMOST, "in script 2 : Parameters passed from 'script part1'  to  'script part2'", _

MsgBox($MB_TOPMOST, "in script 2 : Right part of $CmdLineRaw", _
    StringMid($CmdLineRaw, StringInStr($CmdLineRaw, "[[")))

Local $aArray2 = _ArrayDeclareFromString(StringMid($CmdLineRaw, StringInStr($CmdLineRaw, "[[")))

_ArrayDisplay($aArray2, "in script 2 : Array2", "", $ARRAYDISPLAY_COLALIGNCENTER)
if @error = 1 Then
    MsgBox($MB_TOPMOST, "Error", "Array2 is not an array")

;~ #include <WinAPIShPath.au3>
;~ Local $aData = _WinAPI_CommandLineToArgv($CmdLineRaw)
;~ _ArrayDisplay($aData, '_WinAPI_CommandLineToArgv')


Something strange is why did $CmdLine[1] lose all his double-quotes, even _WinAPI_CommandLineToArgv() which is commented at the end of script 2 shows this ! Gladly the whole string, untouched, is found in the right part of $CmdLineRaw

In case you need to pass other variables between scripts, the syntax found in the following script may help you :

Good luck :)




Link to comment
Share on other sites

Thanks everybody. I will read all your links/advices.
My first script is a tcp server and I would like a second script to handle the "data processing" by this server.
So realtime would be great.


EDIT : So I can't use AutoitObject because the 2 scripts will be compiled. Because of the realtime update, I can't use command line parameters neither.

The array to string function is interesting with _FileWriteFromArray.

Maybe Filemapping could be another solution :

Edit 2 : I can't make FileMapping to work with 2 compiled scripts. It works with one.

Edited by tatane
Link to comment
Share on other sites

Hi all :)
This may interest the readers who (as me) never used until now a compiled script to run another script. Here is the 1st test I just did, based on the 2 scripts found in my precedent post ("script part1.au3" and "script part2.au3"). Actually this is also related to tatane's topic "Communication between 2 scripts"

1) Modify "script part1.au3", changing this :

$iPID = Run(@AutoItExe & " /AutoIt3ExecuteScript " & chr(34) & @ScriptDir & "\script part2.au3" & chr(34) & " " & $sStringFromArray)

To that :

If Not @Compiled Then
    $iPID = Run(@AutoItExe & " /AutoIt3ExecuteScript " & chr(34) & @ScriptDir & "\script part2.au3" & chr(34) & " " & $sStringFromArray)
    $iPID = Run(chr(34) & @ScriptDir & "\script part2.exe" & chr(34) & " " & $sStringFromArray)

2) Compile both scripts to script part1.exe and script part2.exe

3) To make sure no source file will interfere :
Rename script part1.au3, script part2.au3, the whole C:\Program Files\AutoIt3 directory to whatever

4) Double-clic on script part1.exe and everything works fine : the chaining from script part1.exe to script part2.exe works, the array is correctly displayed in script part2.exe as in precedent post :)

5) Revert part 3) to bring back the correct scripts & AutoIt3 directory names & locations.

Now it's time to do a 2nd test, with that #pragma directive, to "allow the compiled executable to execute non compiled scripts", also I'll test .a3x during chaining etc... but anyway, this 1st test "exe => exe" with parameters passed between both .exe did work

When the 2nd test will be done, I'll post the results here, in this same post (no need to create a new post for that). Let's hope I'll be as lucky in the 2nd test as I was in this 1st one :)

Edited by pixelsearch
Link to comment
Share on other sites

The commandline idea is nice but while the OP's requirement of "1000 rows and 4 columns" might not exceed the maximum commandline length with some planning, the method would fail eventually with larger arrays including the element contents.

DDE however is true IPC and would not entail the user having to be careful of exceeding a buffer length.

Edited by Mobius


Link to comment
Share on other sites

@Mobius :
You're right, I tested the 2 precedent scripts on "big" arrays, to find where the limit was :

Local $aArray[555][4]
For $row = 0 to 554
    $aArray[$row][0] = $row & ":" & "0"
    $aArray[$row][1] = 528
    $aArray[$row][2] = 31
    $aArray[$row][3] = "HOSTNAME|1|02:45:47|abcdefgh|username|5"

[555] rows are the limit in script 1, and $array2 will be ok in script 2 when [555] rows are populated like shown.
But if you try [556] rows or more,  an error will happen in script 2, _ArrayDisplay returning @error = 1 (not an array)

So before the error happened, I copied the long variable $CmdLineRaw in a file, to test its length and analyze how it ends :

FileWrite("c:\temp\test.txt", $CmdLineRaw)

Results show that if its length is > 32Kb (that's 556 rows or more) then the error happens because it's an unterminated string.

"AutoIt3 Limits/defaults" in help file shows a 32Kb limitation in these cases :
MAX_ENVSIZE 32767 Maximum size for an ENV variable.
WINTEXTBUFFER 32767 WM_GETTEXT randomly fails if > 32767

Good to know, sky isn't always the limit :)


Link to comment
Share on other sites

Thanks for your time passed on looking at my demand.

Because of the frequent updating I finally chose a txt file save (write only  by the server and read only by the client).

I just convert the array to a string with the function made by jguinch.

Edited by tatane
Link to comment
Share on other sites

  • 2 months later...
On 12/5/2018 at 6:10 AM, Mobius said:

DDE however is true IPC ......

...looking around found this posting and tried the DDE. Found that it does not like the server example compiled as 64 bit.
The client example work compiled as 32 and 64bit.
I don't know anything about DLL calls. Could you fix the UDF to make it 64bit friendly ?
Thanks  :) ( the emoji is to manipulate you emotionally into doing it )  

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

  • Create New...