Jump to content

Share data between 2 instances of a script?


Recommended Posts

Is there a way to share a variable between 2 instaces of the same script?

I need to detect if a script is run twice and the seconds time i need to make something defined by the first instance of the script

#include <Misc.au3>
Global $Running 


If _Singleton( "TestScript", 1 ) = 0 Then
 
 msgbox( 0, "", $Running )
    
Else
 
 $Running = 4
 msgbox( 0, "Test", "TestScript" )
 
EndIf

i would like to have a message box with 4 into the seconde instance of this script, how can i do this?

Stéphane

Link to comment
Share on other sites

What I've done in the past is made a text file that the script can write your variable into and the second time it's run it checks to see if the variable is written there, if it is, do what you need to do otherwise write it.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

File writing isn't the best way to share data between processes because of the internal caching of the OS.

I don't know what more there is to elaborate. You create a hidden window. You watch for a message that you create. You have the second process find your hidden window and send it a message. That's not hard.

Link to comment
Share on other sites

Ok. Could communication be in both ways? Yashied's (nice work) is not example of intercommunication. He is practicing one-way communication.

(I was under impression you were talking about two-way communication)

If you look more closely, then you will understand that the message is sent in both directions. The button "Send" is blocked until receiving a reply message. See also this example.
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...