Jump to content

Pass argument to running script


Recommended Posts

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

For example:

Quote

 

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?

 

Link to comment
Share on other sites

  • Developers

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.

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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 :

;https://autoit.de/index.php/Thread/7492-Prog-%C3%BCbergibt-Parameter-an-seine-1-Instanz-mehrere-Dateien-via-Kontext-Men%C3%BC/
If $CmdLine[0]=0 And @Compiled Then RegWrite("HKEY_CLASSES_ROOT\*\shell\TestContext\command","","REG_SZ",'"' & @AutoItExe & '" "%1"')
;RegDelete("HKEY_CLASSES_ROOT\*\shell\TestContext")

#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
    #NoTrayIcon
    WinWait($WinTitle)
    $Send_handle = WinGetHandle($WinTitle)
    Do
        $ProcList=ProcessList(@ScriptName)
        Sleep(100)
    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
    Exit
EndIf

GUICreate($WinTitle,320,640)
GUIRegisterMsg($WM_COPYDATA, 'MY_WM_COPYDATA');empfängt die Daten
GUISetOnEvent($GUI_EVENT_CLOSE,"_EXIT")
$Liste=GUICtrlCreateLabel($CmdLine[1],0,0,320,640)
GUISetState()

While 1
    Sleep(100)
WEnd

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))
EndFunc

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)
    $Temp=GUICtrlRead($Liste)
    GUICtrlSetData($Liste,$Temp & @CRLF & $COPYDATA_String)
EndFunc

Func _EXIT()
    Exit
EndFunc

it's from eukalyptus, he wrote:

Quote

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

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

Else

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 ?

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