Jump to content

Script interaction (one to another)


Recommended Posts

I'm not even sure I know how to word this... And its probably something that is easy that I'm missing, or impossible and I'm asking too much :)

Say I have one script running. Its in the system tray waiting for user interaction.

Now, say I have another script... and it wants to say "if that first script is running, I want to run function so-and-so in ITS code (not my own code)... if its not running, let me know and I'll do my own thang"

How would I do that? Possible?

Thanks for ideas.

LD

Link to comment
Share on other sites

Yeah, that helps me to know if the other process is running...

but how might I then interact with that process (another AutoIt based program)?

If ProcessExists ("test.exe") Then

RunRemoteFunction ("go")

EndIf

Where "RunRemoteFunction" is the thing I'm looking for :)

LD

Edited by LondonNDIB
Link to comment
Share on other sites

Hey, I think I figured out a solution using hotkeys!!

Set up the first program with a hotkey using HotKeySet for the function I want the other script to eventually call, then have that other script call the function indirectly by envoking the hotkey, using Send!!!

It would be nice to have it done more directly though. One possible problem I haven't tested for but could see... is what if this is all happening while running in the background as a service with no desktop interaction? And that will be the case with what I'm doing. So I would very much prefer a direct execution of the "other" script's function if at all possible.

Again... Script A is running and has a function. Script B wants to get Script A to call that function. Its not the same thing as having Script B call Script A's function (if that were the case, I'd just add the function to Script :).

So still - any idea would be appreciated.

In the meantime I'll continue to test.

LD

Edited by LondonNDIB
Link to comment
Share on other sites

ummm maybe a .ini file would work? umm, it may slow it down a bit because it'd constantly be having to open and close it lol

Yeah... like the HotKeys thing, I don't think its ideal - but it probably won't have the same desktop interaction problem (if run as service) as my HotKeys solution might... so thanks! I'll give that a shot if I can't figure out a better way.

Now keep in mind that you are the one that said any idea. :-)

Lol... love the way you put that. I glanced at the link and didn't immediately see anything that applies to this situation. I'll look at it again tomorrow when I have some time!

Thanks!

LD

Link to comment
Share on other sites

I have an idea, no clue if it will work but an idea none the less. Would it be possible to create a DllStruct, create a pointer to a variable in the DllStruct, pass that in an ini file then ditch the ini file and query the variable directly by using it pointer? Would be much faster then ini or hotkey i think, only major problem i can think of is i dont think there is a func in autoit to read a variable using its memory address (pointer), i maybe mistaken i would take a look at how the memory hacking thread, i think its titled "Hacking Autoit!" in the example forums work.

Another option would be to send signals via the ftp or http or some network protocol, one program sends the signals and the other listens to x port for the signals, just send them to 127.0.0.1. Not shure if tis would be faster than ini, but i would create disk usage :) .

Well thats all i can think of at the moment.

EDIT: Had another idea, post signals on the clip board. ClipPut() and ClipGet()

Edited by smstroble

MUHAHAHAHAHA

Link to comment
Share on other sites

...I glanced at the link and didn't immediately see anything that applies to this situation. I'll look at it again tomorrow when I have some time!...

Near the bottom of the Func - look at AutoIt3ExecuteScript. SmOke_N has the main script launch 2 "children" scripts. The main one reads the output of the second child via the STDIO functions. [i wish that I could read my second child that easily.]

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Woot, i got a working example for ya. I used ClipPut/ClipGet to pass the control id, and ControlSetText/ControlGetText to pass signals and an invisible label to handle the messages.

The reciving script.

HotKeySet("{ESC}", "quit")
GUICreate("12345")
$control = GUICtrlCreateLabel("1", -1, -1)
ClipPut($control)

While 1
    $text = ControlGetText("12345", "", $control)
    If $text = "message1" Then
        MsgBox(0, "", "do someting")
        ControlSetText("12345", "", $control, "1")
    ElseIf $text = "message2" Then
        MsgBox(0, "", "do something else")
        ControlSetText("12345", "", $control, "1")
    EndIf
    sleep(100)
WEnd
    
Func quit()
    Exit
EndFunc
oÝ÷ Ù8^±éÝx,r¸©µ«­¢+Ø(ÀÌØí½¹Ñɽ°ô
±¥ÁÐ ¤(ÀÌØí½¹Ñɽ°ôÀÌØí½¹Ñɽ°¬À)
½¹Ñɽ±MÑQáÐ ÅÕ½ÐìÄÈÌÐÔÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÀÌØí½¹Ñɽ°°ÅÕ½ÐíµÍÍÄÅÕ½Ðì¤)ͱÀ ÌÀÀÀ¤)
½¹Ñɽ±MÑQáÐ ÅÕ½ÐìÄÈÌÐÔÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÀÌØí½¹Ñɽ°°ÅÕ½ÐíµÍÍÈÅÕ½Ðì¤)á¥Ð(

:)

Edited by smstroble

MUHAHAHAHAHA

Link to comment
Share on other sites

Yet one more option - GUI controls. One script can click buttons, write/read edit and input boxes, etc. on another script's GUI. I did demo scripts for someone else and posted them in the Example Scripts section.

:)

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 appreciate all the suggestions!

I think I should spell out EXACTLY what I'm doing, so maybe it will trigger yet another creative solution that will work best!

First off, I may be using the term "script" too loosely. In all occasions, I mean a compiled exe.

Its not really two scripts, its two instances of the same script.

If the script is called without any parameters, it simply starts a tray icon menu that the user can interact with to call certain functions. Alternatively, the user can call the script with a command line parameter to jump directly to one of the functions.

The problem is - I NEVER want two copies of the script running at once for fear of conflict within said functions... so if they are running at once, it should be under very controlled and brief circumstances.

So I have a whole much of if/switch/etc controls.

The scenario I'm trying to address currently, is if the program IS running as a tray icon, and then it is called again with a command line parameter (because, for example, it is a scheduled task). In this case, I want the tray menu to remain and the new one to be destroyed... that's easy enough, but before it is destroyed, I want it to pass on what it was trying to do (via the parameter) to the tray menu version and have it begin that task.

I hope that makes sense.

So, the GUI idea won't work for me because there is no GUI nor will their be (unless you're suggesting some hidden way of doing it).

EnvSet/Get, writing/reading a file, ClipPut/Get and my own HotKey idea all work (I've tested each) and here are my concerns:

HotKey, EnvSet/Get (or GUI): Will this work if the user calls the tray icon, then the scheduler runs the parameter version as a service? Will the two be aware of each other since they are running at different levels and/or as different users? Ie. will the HotKey be passed, will the Env be global enough, will the GUI be appliciable when the service doesn't have a desktop?

File write/read: Slow is the least worry... its not like its happening 100 times a second. My bigger worry is that the OS, the user, or some virus scanner deletes or otherwise makes said file inaccessible.

ClipPut/Get: It worked... but I can't help but to wonder if the user will happen to copy something totally unrelated to the clipboard that will mess it up.

Thanks again for all the help!

More ideas are welcome, but I have enough here to keep me testing for a week!! If anyone has experience and can address those concerns above, that would be great and save me some time. Thanks!!

LD

Link to comment
Share on other sites

Thanks, but the trouble isn't how to detect/know if its already running... I got that part down. Its just how to pass the desired task from the new one to the existing one.

LD

yeah - sorry. that sunk in after I made that worthless post :-(

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Great!

Just thinking out loud here... so maybe flawed.

Always launch via a main exe script.

Have that main exe script:

launch a child exe script - if not already running

If the child script is already running - pass parameters via STDIO

Edit: NVM; building a demo ran into the problems you posted about...

Move over, I need some space to bang my head on your brick wall. :-(

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

So, the GUI idea won't work for me because there is no GUI nor will their be (unless you're suggesting some hidden way of doing it).

A hidden GUI was exactly what I was thinking. But I had to settle for Minimized to access the controls.

I used _Singleton() on start up to determine if it's the first instance or not.

The first instance reacts to any command line parameters of its own and then maintains the GUI.

Any late instances only pass their parameters to the GUI and exit.

The first instance reacts to any parameters passed to it via the GUI, and exits when passed a "/quit" parameter.

#include <misc.au3>
#include <array.au3>

$WinTitle = StringTrimRight(@ScriptName, 4)
$WinText = $WinTitle & " input GUI"
Global $Inputs[1] = [0]

If _Singleton($WinTitle, 1) Then
    ; -----------------------------
    ; First instance, create GUI
    ; -----------------------------
    $hGUI = GUICreate($WinTitle, 400, 100)
    $Label1 = GUICtrlCreateLabel($WinText, 20, 20, 360, 20)
    $Edit1 = GUICtrlCreateInput("", 20, 60, 360, 20)
    GUISetState()
    WinSetState($WinTitle, $WinText, @SW_MINIMIZE)
    
    ; Save any commandline parameters passed
    If $CmdLine[0] Then
        $Inputs = $CmdLine
        _ProcessInputs()
    EndIf
    
    ; Main loop waiting for inputs from other instances
    While 1
        If GUICtrlRead($Edit1) <> "" Then
            Sleep(100) ; Other instance has 100ms to complete writing to Edit1
            $Inputs = StringSplit(GUICtrlRead($Edit1), "::", 1)
            _ProcessInputs()
        EndIf
        Sleep(100)
    WEnd
Else
    ; -----------------------------
    ; Late instance, only pass parameters to GUI and exit
    ; -----------------------------
    If WinExists($WinTitle, $WinText) Then
        If $CmdLine[0] Then
            $Msg = ""
            For $n = 1 To $CmdLine[0]
                $Msg &= $CmdLine[$n] & "::"
            Next
            $Msg = StringTrimRight($Msg, 2)
            ControlSetText($WinTitle, $WinText, "Edit1", $Msg)
        EndIf
    Else
        MsgBox(16, "Singleton Error", $WinTitle & " is already running, but GUI is not present.")
    EndIf
    Exit
EndIf


; ---------------------------------------------
; Function _ProcessInputs()
;   Handle processing of the $Inputs array.
;   If any parameter = "/Quit" then exit after processing the rest
;   For demo, just displays them in a TrayTip.
; ---------------------------------------------
Func _ProcessInputs()
    Local $n, $Msg = "", $Quit = False
    For $n = 1 To $Inputs[0]
        If $Inputs[$n] = "/Quit" Then
            $Quit = True
            ContinueLoop
        EndIf
        $Msg &= "Input[" & $n & "] = " & $Inputs[$n] & @CRLF
    Next
    TrayTip($WinTitle, $Msg, 10)
    GUICtrlSetData($Edit1, "")
    If $Quit Then
        ; Delay if there were other parameters to display
        If $Inputs[0] > 1 Then Sleep(2000)
        Exit
    EndIf
EndFunc   ;==>_ProcessInputs

Compile this script and then run it, with or without command line parameters.

You'll see a minimized GUI on the Task Bar, that's how the late instances communicate with the first instance.

Run the .exe again with or without parameters to see them getting passed to the first instance.

When you get tired of it just run another instance with "/quit" as one of the parameters.

Enjoy!

:)

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

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