Pass argument to running script

9 posts in this topic

Is it possible to pass some information to existing running script by execute second instance of same script with cmd parameters?

For example:



1. Run example.exe (with no cmd params)

2. Run example.exe again (with cmd params "test")

3. Read "test" by first instance of example.exe


Any idea?


Share this post

Link to post
Share on other sites

No, that doesn't work like that. You can always build a communication method to a running script.
There are several examples posted on how to do that.



Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)

I found a script starting multiple instances via Context-Menu (multiple Files selected in Explorer), first 1 Instance creates Gui all other send's there cmdline[1] to the Instance 1. It's old an i haven't test it, it runs only in compiled mode :

If $CmdLine[0]=0 And @Compiled Then RegWrite("HKEY_CLASSES_ROOT\*\shell\TestContext\command","","REG_SZ",'"' & @AutoItExe & '" "%1"')

#include <Misc.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

If $CmdLine[0]<>1 Then Exit

Global $WinTitle="Window Title"

If _Singleton($WinTitle,1)=0 Then ;wenn nicht 1 Instanz
    $Send_handle = WinGetHandle($WinTitle)
    Until $ProcList[2][1]=@AutoItPID ;wartet bis aktuelle Instanz an der Reihe ist - also [2][0], [1][0] ist ja die 1 Instanz mit GUI
    _SendCopyDataString(0,$Send_handle,$CmdLine[1]);sendet den Commandline-Parameter an das GUI der 1 Instanz

GUIRegisterMsg($WM_COPYDATA, 'MY_WM_COPYDATA');empfängt die Daten

While 1

Func _SendCopyDataString($My_Hwnd, $Scite_hwnd, $sCmd)
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
            'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
            'Ptr', DllStructGetPtr($COPYDATA))

Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $Temp=""
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    Local $COPYDATA_StringLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char['&$COPYDATA_StringLen&']', DllStructGetData($COPYDATA, 3))
    $COPYDATA_String = StringLeft(DllStructGetData($CmdStruct, 1), $COPYDATA_StringLen)
    GUICtrlSetData($Liste,$Temp & @CRLF & $COPYDATA_String)

Func _EXIT()

it's from eukalyptus, he wrote:


wers ausprobieren will:
als EXE Compilieren
dann einmal direkt aufrufen, damit der Eintrag ins Kontext-Menü gemacht wird
danach im Explorer irgendwelche Dateien markieren -> Rechtsklick -> TestKontext

das GUI listet nun die Dateien der Reihe nach auf.

Ich hoff, das kann jemand brauchen ;)

if somebody will try it

compile to exe

start once for creating a new Contextmenu Item

after select multiple files in Explorer -> RightClick -> TestKontext

the files are listed in the Gui

hope it's helpfull for somebody ;)

Edited by AutoBert

Share this post

Link to post
Share on other sites

Why would you need that ? It can be done , but there are more easier and elegant ways like. What exactly do you want to accomplish ?

Share this post

Link to post
Share on other sites

All I want to achieve is to read "Reply-To" field from selected message in Thunderbird grid and pass this value to running AutoIt script - that's all.

My solution so far is:

1. I have installed add-on for Thunderbird called "Custom Buttons" which help me to read "Reply-To" value and pass it as a parameter to specified exe file (Autoit script).

2. When Autoit script starts (with parameter),it close other instance of same script if already running (here I wanted to avoid close other instance and keep running existing one and read that value other way)

3. Read received parameter and refresh data on Autoit scripts

Share this post

Link to post
Share on other sites

And what does the exe file do with the email address ? When does the exe finish ?


Share this post

Link to post
Share on other sites

Exe file shows info according to email address from sql database. Exe never finish, want to keep it active all the time and just reload data when input change (Reply-To e-mail address)

Share this post

Link to post
Share on other sites

So do it like this :

If there is a parameter - write the value to the registry and then exit the script


here is your infinite loop. Inside put a read from the value of the registry and after that delete the value

That is it.

So you exe will be running with no parameters. Then you start another instance of the same exe , this time with a parameter. It writes the email to the registry (or somewhere) and then exits. The original script picks up that there is a new value and refreshes.

Did you get it ?

Share this post

Link to post
Share on other sites

Yes I get it, thank you for suggestion.

Share this post

Link to post
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