obj := {base:{__Set: Func("StdOutHandling")}}
CmdRet("ping -n 10 8.8.8.8", obj)
ToolTip
MsgBox, % obj.StdOut
StdOutHandling(this, key, value) {
if (key = "_StdOut") {
ToolTip % value ; здесь можно совершать какие-то действия со значением, например, сохранять в другом ключе
this.StdOut .= value
Return 0
}
}
CmdRet(sCmd, obj)
{
static STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
DllCall("CreatePipe", PtrP, hPipeRead, PtrP, hPipeWrite, UInt, 0, UInt, 0)
DllCall("SetHandleInformation", Ptr, hPipeWrite, UInt, 1, UInt, 1)
VarSetCapacity(pi, A_PtrSize*2 + 4*2, 0) ; _PROCESS_INFORMATION
VarSetCapacity(si, sisize := A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
NumPut(sisize, si)
NumPut(STARTF_USESTDHANDLES, si, A_PtrSize*4 + 4*7)
NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*3)
NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*4)
if !DllCall("CreateProcess", UInt, 0, Ptr, &sCmd, UInt, 0, UInt, 0, Int, True
, UInt, CREATE_NO_WINDOW, UInt, 0, UInt, 0, Ptr, &si, Ptr, &pi) {
DllCall("CloseHandle", Ptr, hPipeRead)
DllCall("CloseHandle", Ptr, hPipeWrite)
MsgBox, CreateProcess is failed
Return
}
DllCall("CloseHandle", Ptr, hPipeWrite)
VarSetCapacity(sTemp, 4096), nSize := 0
while DllCall("ReadFile", Ptr, hPipeRead, Ptr, &sTemp, UInt, 4096, UIntP, nSize, UInt, 0)
sOutput .= (obj._StdOut := StrGet(&sTemp, nSize, "CP866"))
DllCall("CloseHandle", Ptr, NumGet(pi, 0))
DllCall("CloseHandle", Ptr, NumGet(pi, A_PtrSize))
DllCall("CloseHandle", Ptr, hPipeRead)
Return sOutput
}