I am using this which works great in script 1:
Code: Select all
FileAppend, % "Some text", *
Code: Select all
FileAppend, % "Some text", *
Why do you think so? It definitely does:doubledave22 wrote: ↑However it seems that script 2's fileappend * command doesn't end up writing to the stdout
Code: Select all
script := "FileAppend, Auto, *" . "`n"
. "FileAppend, Hot, *" . "`n"
. "FileAppend, key, *"
Shell := ComObjCreate("WScript.Shell")
Exec := Shell.Exec(A_AHKPath . " *")
Exec.StdIn.Write(script)
Exec.StdIn.Close()
StdOut := Exec.StdOut
str := ""
while !StdOut.AtEndOfStream
str .= StdOut.ReadLine()
MsgBox, % str
Code: Select all
script =
(
FileAppend, Auto, *
Sleep, 1000
FileAppend, Hot, *
Sleep, 1000
FileAppend, key, *
)
DynaRunReadStdOut(script, "ShowStdOutFromChild")
ShowStdOutFromChild(out := "") {
static EM_SETSEL := 0xB1, EM_REPLACESEL := 0xC2
, hGui, _ := ShowStdOutFromChild()
if !hGui {
Gui, New, +hwndhGui +AlwaysOnTop +LabelConsole, My Console
Gui, Font, s10, Lucida Console
Gui, Add, Edit, w300 h200
Gui, Show
}
SendMessage, EM_SETSEL, -2, -1, Edit1, ahk_id %hGui%
SendMessage, EM_REPLACESEL, false, &out, Edit1, ahk_id %hGui%
}
ConsoleClose() {
ExitApp
}
DynaRunReadStdOut(script, callBack := "", encoding := "CP0", args*)
{
static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
, STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
, params := [ "UInt", PIPE_ACCESS_OUTBOUND := 0x2, "UInt", 0
, "UInt", PIPE_UNLIMITED_INSTANCES := 255, "UInt", 0
, "UInt", 0, "Ptr", 0, "Ptr", 0, "Ptr" ]
, BOM := Chr(0xFEFF)
DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
VarSetCapacity(STARTUPINFO , siSize := A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
NumPut(siSize , STARTUPINFO)
NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
NumPut(hPipeWrite , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
NumPut(hPipeWrite , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)
pipeName := "AHK_" . A_TickCount
for k, v in ["pipeGA", "pipe"]
%v% := DllCall("CreateNamedPipe", "Str", "\\.\pipe\" . pipeName, params*)
sCmd := A_AhkPath . " ""\\.\pipe\" . pipeName . """"
for k, v in args
sCmd .= " """ . v . """"
if !DllCall("CreateProcess", "UInt", 0, "Str", sCmd, "UInt", 0, "UInt", 0, "Int", true, "UInt", CREATE_NO_WINDOW
, "UInt", 0, "UInt", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
{
DllCall("CloseHandle", "Ptr", hPipeRead)
DllCall("CloseHandle", "Ptr", hPipeWrite)
for k, v in ["pipeGA", "pipe"]
DllCall("CloseHandle", "Ptr", %v%)
throw "CreateProcess failed"
}
DllCall("CloseHandle", "Ptr", hPipeWrite)
for k, v in ["pipeGA", "pipe"]
DllCall("ConnectNamedPipe", "Ptr", %v%, "Ptr", 0)
tempScript := BOM . script
tempScriptSize := ( StrLen(tempScript) + 1 ) << !!A_IsUnicode
DllCall("WriteFile", "Ptr", pipe, "Str", tempScript, "UInt", tempScriptSize, "UIntP", 0, "Ptr", 0)
for k, v in ["pipeGA", "pipe"]
DllCall("CloseHandle", "Ptr", %v%)
VarSetCapacity(sTemp, 4096), nSize := 0
while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
( callBack && %callBack%(stdOut) )
}
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
DllCall("CloseHandle", "Ptr", hPipeRead)
Return sOutput
}
Code: Select all
script =
(
#Persistent
FileAppend, Auto, *
sleep, 1000
FileAppend, Hot, *
sleep, 1000
FileAppend, key, *
)
I think no way. But you still can use GUI to display any text you want from inside the script.doubledave22 wrote: ↑Is there a way to only change the second/child script to attach a separate debugger?
A console can be attached to any number of processes. This would attach the script's process to the console of the parent process, if it has one:teadrinker wrote: ↑20 Sep 2021, 21:00Of course, the console can only be attached to one process, the child script is running as a separate process.
Code: Select all
DllCall("AttachConsole", "int", -1)
Code: Select all
RunInheritHandles(cmd, workingDir:="") {
VarSetCapacity(pi, 24, 0), VarSetCapacity(si, si_size := 32+9*A_PtrSize, 0)
p := NumPut(si_size , si) ; size of si
p := NumPut(0x100 , p+3*A_PtrSize+28, "uint") ; dwFlags = STARTF_USESTDHANDLES
p += 2*A_PtrSize
Loop 3
p := NumPut(DllCall("GetStdHandle", "int", -9-A_Index, "ptr"), p+0)
If !DllCall("CreateProcess", "ptr", 0, "ptr", &cmd, "ptr", 0, "ptr", 0
, "int", true, "uint", 0, "ptr", 0, "ptr", workingDir!="" ? &workingDir : 0
, "ptr", &si, "ptr", &pi)
Return
DllCall("CloseHandle", "ptr", NumGet(pi, 0)) ; hProcess
DllCall("CloseHandle", "ptr", NumGet(pi, A_PtrSize)) ; hThread
}
Code: Select all
if (!A_Args.Length()) {
FileAppend PARENT`n, *
cmd = "%A_AhkPath%" "%A_ScriptFullPath%" 1
RunInheritHandles(cmd)
MsgBox ; SciTE will not show output after the parent process exits.
} else {
FileAppend CHILD`n, *
}
Code: Select all
; Scintilla expects an 8-bit string (probably UTF-8?) even though
; EM_REPLACESEL should accept UTF-16 for Unicode apps such as SciTE.
VarSetCapacity(s8, StrPut(s, "UTF-8"), 1), StrPut(s, &s8, "UTF-8")
Control EditPaste, % s8, Scintilla2, ahk_class SciTEWindow
That is the only thing you need to do. Just replace Run with RunInheritHandles. Run's first two parameters should correspond directly to the function's parameters. However:doubledave22 wrote: ↑25 Sep 2021, 09:35Also do I need to use RunInheritHandles in place of the run command to load the child script?
Ok, I have worked through replacing the run with RunInheritHandles and worked out the correct cmd but I think I will need OutputVarPID still.
Code: Select all
hProcess := NumGet( pi, 0 )
msgbox, % hProcess