Edit: Simplified example
Code: Select all
#Include ExecScript.ahk
code := "
(Join`n
FileAppend [Child script] Hello!!``n, *
if (A_AhkVersion < 2)
{
A_Args := []
Loop `%0`%
A_Args[A_Index] := `%A_Index`%
}
for i, arg in A_Args
{
FileAppend [Child script] `%i`% = `%arg`%``n, *
Sleep 750
}
working_dir := (A_AhkVersion < 2) ? A_WorkingDir : A_InitialWorkingDir
FileAppend [Child script] Working Directory: `%working_dir`%``n, *
Sleep 750
FileAppend [Child script] AutoHotkey.exe: `%A_AhkPath`%``n, *
Sleep 750
FileAppend [Child script] AutoHotkey version: `%A_AhkVersion`%``n, *
Sleep 750
FileAppend [Child script] Goodbye!!``n, *
return
)"
;// Exec child script
script := ExecScript(code, ["Param One", "Param Two", "Param Three"])
SetTimer Poll, -100 ;// start a separate thread
Gui New
Gui Font, s10, Consolas
Gui Margin, 0, 0
Gui Add, Edit, HwndhEdit w500 r15
Gui Show
EditAppendLine(hEdit, "[Main script] End of auto-execute section")
return
GuiClose:
ExitApp
;// Read StdOut and/or StdErr
Poll:
EditAppendLine(hEdit, "[Main script] Poll Thread Start")
while (script.Status != 1) ;// http://goo.gl/g45DXO
if ( (out := script.StdOut.ReadLine()) != "" )
EditAppendLine(hEdit, out)
if ( (err := script.StdErr.ReadAll()) != "" )
EditAppendLine(hEdit, err)
EditAppendLine(hEdit, "[Main script] Poll Thread Done")
return
EditAppendLine(hEdit, line)
{
pLine := &(line .= "`r`n")
SendMessage, 0x000E, 0, 0,, ahk_id %hEdit% ; WM_GETTEXTLENGTH
SendMessage, 0x00B1, %ErrorLevel%, %ErrorLevel%,, ahk_id %hEdit% ; EM_SETSEL
SendMessage, 0x00C2, 0, %pLine%,, ahk_id %hEdit% ; EM_REPLACESEL
}