Post by garry » 15 May 2022, 08:29
von SKAN
Code: Select all
;-------- saved at 2021-05-31 07:46 UTC --------------
;- SKANXXX
;- RunCMD() v0.94 : Capture stdout to variable. Non-blocking version. Pre-process/omit individual lines.
;- https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74647
#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Menu, Tray, Icon, %A_Comspec%
Process, Priority,,High
CPX:="cp" . DllCall("GetOEMCP", "UInt") ;- get CODEPAGE e.g. cp850 / use CP850 below in function RunCmd
;---------------------------------------
;source13=%a_desktop% ;
;dest13 =F:\_BEELINK\DESKTOP ;
;cmdx=robocopy "%source13%" "%dest13%" /XO /E /TEE /UNICODE
cmdx=ping www.autohotkey.com -n 4
;---------------------------------------
Gui, Margin, 15, 15
Gui, Font, s9, Consolas
Gui, Add, Text,, Output
Gui, Add, Edit, y+3 -Wrap +HScroll R20 HwndhEdit1, % Format("{:81}", "")
ControlGetPos,,,W,,,ahk_id %hEdit1%
Gui, Add, Text,, Command Line
Gui, Add, Edit, y+3 -Wrap HwndhEdit2 w%W%,%cmdx%
Gui, Add, Button, x+0 w0 h0 Default gRunCMD, <F2> RunCMD
Gui, Add, StatusBar
SB_SetParts(200,200), SB_SetText("`t<Esc> Cancel/Clear", 1), SB_SetText("`t<Enter> RunCMD", 2)
GuiControl,, Edit1
Gui, Show,, RunCMD() - Realtime per line streaming demo
return
;-----
RunCMD:
SB_SetText("", 3)
GuiControlGet, Cmd,, %hEdit2%
GuiControl, Disable, Button1
ExitCode := RunCMD(A_Comspec . " /c " . Cmd)
SB_SetText("`tExitCode : " ErrorLevel, 3)
GuiControl, Enable, Button1
Edit_Append(hEdit2,"")
GuiControl, Focus,Edit2
Return
;------------------------------
#IfWinActive RunCMD() ahk_class AutoHotkeyGUI
Esc::
GuiControl, Focus,Edit2
Edit_Append(hEdit2,"")
If (A_Args.RunCMD.PID)
{
A_Args.RunCMD.PID := 0
Return
}
SB_SetText("", 3)
GuiControl,,Edit1
GuiControl,,Edit2
Return
;------------------------------
#IfWinActive
RunCmd_Output(Line, LineNum) {
Global
If ( SubStr(Line,-1)!="`r`n" )
Line .= "`r`n"
Edit_Append(hEdit1, Line)
}
Edit_Append(hEdit, Txt) { ; Modified version by SKAN
Local ; Original by TheGood on 09-Apr-2010 @ autohotkey.com/board/topic/52441-/?p=328342
L := DllCall("SendMessage", "Ptr",hEdit, "UInt",0x0E, "Ptr",0 , "Ptr",0) ; WM_GETTEXTLENGTH
DllCall("SendMessage", "Ptr",hEdit, "UInt",0xB1, "Ptr",L , "Ptr",L) ; EM_SETSEL
DllCall("SendMessage", "Ptr",hEdit, "UInt",0xC2, "Ptr",0 , "Str",Txt) ; EM_REPLACESEL
}
;===================================================================================================
;RunCMD(CmdLine, WorkingDir:="", Codepage:="CP0", Fn:="RunCMD_Output") { ; RunCMD v0.94
RunCMD(CmdLine, WorkingDir:="", Codepage:="CP850", Fn:="RunCMD_Output") {
Local ; RunCMD v0.94 by SKAN on D34E/D37C @ autohotkey.com/boards/viewtopic.php?t=74647
Global A_Args ; Based on StdOutToVar.ahk by Sean @ autohotkey.com/board/topic/15455-stdouttovar
Fn := IsFunc(Fn) ? Func(Fn) : 0
, DllCall("CreatePipe", "PtrP",hPipeR:=0, "PtrP",hPipeW:=0, "Ptr",0, "Int",0)
, DllCall("SetHandleInformation", "Ptr",hPipeW, "Int",1, "Int",1)
, DllCall("SetNamedPipeHandleState","Ptr",hPipeR, "UIntP",PIPE_NOWAIT:=1, "Ptr",0, "Ptr",0)
, P8 := (A_PtrSize=8)
, VarSetCapacity(SI, P8 ? 104 : 68, 0) ; STARTUPINFO structure
, NumPut(P8 ? 104 : 68, SI) ; size of STARTUPINFO
, NumPut(STARTF_USESTDHANDLES:=0x100, SI, P8 ? 60 : 44,"UInt") ; dwFlags
, NumPut(hPipeW, SI, P8 ? 88 : 60) ; hStdOutput
, NumPut(hPipeW, SI, P8 ? 96 : 64) ; hStdError
, VarSetCapacity(PI, P8 ? 24 : 16) ; PROCESS_INFORMATION structure
If not DllCall("CreateProcess", "Ptr",0, "Str",CmdLine, "Ptr",0, "Int",0, "Int",True
,"Int",0x08000000 | DllCall("GetPriorityClass", "Ptr",-1, "UInt"), "Int",0
,"Ptr",WorkingDir ? &WorkingDir : 0, "Ptr",&SI, "Ptr",&PI)
Return Format("{1:}", "", ErrorLevel := -1
,DllCall("CloseHandle", "Ptr",hPipeW), DllCall("CloseHandle", "Ptr",hPipeR))
DllCall("CloseHandle", "Ptr",hPipeW)
, A_Args.RunCMD := { "PID": NumGet(PI, P8? 16 : 8, "UInt") }
, File := FileOpen(hPipeR, "h", Codepage)
, LineNum := 1, sOutput := ""
While (A_Args.RunCMD.PID + DllCall("Sleep", "Int",0))
and DllCall("PeekNamedPipe", "Ptr",hPipeR, "Ptr",0, "Int",0, "Ptr",0, "Ptr",0, "Ptr",0)
While A_Args.RunCMD.PID and (Line := File.ReadLine())
sOutput .= Fn ? Fn.Call(Line, LineNum++) : Line
A_Args.RunCMD.PID := 0
, hProcess := NumGet(PI, 0)
, hThread := NumGet(PI, A_PtrSize)
, DllCall("GetExitCodeProcess", "Ptr",hProcess, "PtrP",ExitCode:=0)
, DllCall("CloseHandle", "Ptr",hProcess)
, DllCall("CloseHandle", "Ptr",hThread)
, DllCall("CloseHandle", "Ptr",hPipeR)
, ErrorLevel := ExitCode
Return sOutput
}
;==================================================================================================
von TEADRINKER (z.B. für schnelle Abläufe wie robocopy weniger geeignet , function AddOutputInGui evtl so anpassen dass er alle 5 Sekunden text an EDIT übermittelt (?) )
Code: Select all
;- Hide command console when using RunWaitOne() example / from user teadrinker
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84266&sid=eff012cadb7a851b2c18f5f03b68408f
;----------------------------------------------
;- CREATED = 20201211 from user 'teadrinker'
;----------------------------------------------
cmdx:="ping autohotkey.com -n 3&&ver&&systeminfo" ;- <<<< here your command
;cmdx:="dir"
;============== GUI ===========
#warn
#noenv
Fileencoding,UTF-8
name1:="DOS_TEST"
global name1
e:=""
CPX:="cp" . DllCall("GetOEMCP", "UInt") ;- get CODEPAGE e.g. cp850
;CPX:="cp65001"
setworkingdir,%a_scriptdir%
Gui,1:default
Gui,1: -dpiscale
Gui,1:Color,Black,Black ; GUI black / EDIT is BLACK
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
;- maybe change fontsize depending scaling ( this is not calculated )
;============ GUISIZEx DPIx 4Kx 3840*2160 is 100% ============
if (wa=3840)
Gui,1:Font,s12 cYellow,Lucida Console
;============ GUISIZEx DPIx FHD 1920*1080 is 100% ============
else if (wa=1920)
Gui,1:Font,s10 cYellow,Lucida Console
else
Gui,1:Font,s8 cYellow,Lucida Console
;=============================================================
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*70)/xx,h:=(ha*60)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED1 ;- here the output
x:=(wa*1)/xx,y:=(ha*63)/xx,w:=(wa*65)/xx,h:=(ha*6)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED2,%cmdx% ;- add CMDx command above / or input command
x:=(wa*67)/xx,y:=(ha*63)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui, add, Edit, x%x% y%y% w%w% h%h% vED3, ;- ENDED
x:=(wa*67)/xx,y:=(ha*66)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui,add,button, x%x% y%y% w%w% h%h% gPrintx, PRINT
x:=(wa*2)/xx,y:=(ha*2)/xx,w:=(wa*75)/xx,h:=(ha*75)/xx
Gui, Show,x%x% y%y% w%w% h%h%,%name1%
gosub,a0 ;- remove this if add other commands below
GuiControl,1: Focus,ED2
return
;-------------------------
Guiclose:
Exitapp
esc::exitapp
;-------------------------
~$enter::
gosub,a0
return
;=========================================================
AddOutputInGui(output) {
Control, EditPaste, %output%`r`n, Edit1,%name1% ;- display output in 1st EDIT
}
;=========================================================
A0:
Gui,1:submit,nohide
Guicontrol,1:,ED3,...running
ed2a:="cmd /c " . ed2
xxc:=cmdret(ED2a, Func("AddOutputInGui"),CPX)
e .="`r`n===============================`r`n" . ed2 . " =`r`n-------------------------------`r`n" . xxc . "`r`n===============================`r`n"
e := RegExReplace(e, "((^)|\R)\h*(?=\R|$)(?(2)\R)") ;- remove empty lines
gosub,clear
;gosub,printx
return
;-------------------------
CLEAR:
Gui,1:submit,nohide
Guicontrol,1:,ED2,
Guicontrol,1:,ED3,ENDED
GuiControl,1: Focus,ED2
return
;-------------------------
printx:
f1=%a_desktop%\%a_now%_DOS_SCREEN_OUTPUT.txt
Gui,1:submit,nohide
if e<>
{
fileappend,%e%,%f1%,utf-8
run,%f1%
e:=""
}
return
;=========================================================
CmdRet(sCmd, callBackFuncObj := "", encoding := "CP0") ;- teadrinker https://www.autohotkey.com/boards/viewtopic.php?p=369467#p369467
{
static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
, STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
hPipeRead:=""
hPipeWrite:=""
sOutput:=""
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)
if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
, "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
{
DllCall("CloseHandle", "Ptr", hPipeRead)
DllCall("CloseHandle", "Ptr", hPipeWrite)
throw Exception("CreateProcess is failed")
}
DllCall("CloseHandle", "Ptr", hPipeWrite)
VarSetCapacity(sTemp, 4096), nSize := 0
while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
;sOutput .= stdOut := StrGet(&sTemp, nSize)
;sOutput .= stdOut := StrGet(&sTemp, nSize, CPX)
( callBackFuncObj && callBackFuncObj.Call(stdOut) )
}
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
DllCall("CloseHandle", "Ptr", hPipeRead)
Return sOutput
}
;================= END SCRIPT ========================================================================
von SKAN
[code];-------- saved at 2021-05-31 07:46 UTC --------------
;- SKANXXX
;- RunCMD() v0.94 : Capture stdout to variable. Non-blocking version. Pre-process/omit individual lines.
;- https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74647
#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Menu, Tray, Icon, %A_Comspec%
Process, Priority,,High
CPX:="cp" . DllCall("GetOEMCP", "UInt") ;- get CODEPAGE e.g. cp850 / use CP850 below in function RunCmd
;---------------------------------------
;source13=%a_desktop% ;
;dest13 =F:\_BEELINK\DESKTOP ;
;cmdx=robocopy "%source13%" "%dest13%" /XO /E /TEE /UNICODE
cmdx=ping www.autohotkey.com -n 4
;---------------------------------------
Gui, Margin, 15, 15
Gui, Font, s9, Consolas
Gui, Add, Text,, Output
Gui, Add, Edit, y+3 -Wrap +HScroll R20 HwndhEdit1, % Format("{:81}", "")
ControlGetPos,,,W,,,ahk_id %hEdit1%
Gui, Add, Text,, Command Line
Gui, Add, Edit, y+3 -Wrap HwndhEdit2 w%W%,%cmdx%
Gui, Add, Button, x+0 w0 h0 Default gRunCMD, <F2> RunCMD
Gui, Add, StatusBar
SB_SetParts(200,200), SB_SetText("`t<Esc> Cancel/Clear", 1), SB_SetText("`t<Enter> RunCMD", 2)
GuiControl,, Edit1
Gui, Show,, RunCMD() - Realtime per line streaming demo
return
;-----
RunCMD:
SB_SetText("", 3)
GuiControlGet, Cmd,, %hEdit2%
GuiControl, Disable, Button1
ExitCode := RunCMD(A_Comspec . " /c " . Cmd)
SB_SetText("`tExitCode : " ErrorLevel, 3)
GuiControl, Enable, Button1
Edit_Append(hEdit2,"")
GuiControl, Focus,Edit2
Return
;------------------------------
#IfWinActive RunCMD() ahk_class AutoHotkeyGUI
Esc::
GuiControl, Focus,Edit2
Edit_Append(hEdit2,"")
If (A_Args.RunCMD.PID)
{
A_Args.RunCMD.PID := 0
Return
}
SB_SetText("", 3)
GuiControl,,Edit1
GuiControl,,Edit2
Return
;------------------------------
#IfWinActive
RunCmd_Output(Line, LineNum) {
Global
If ( SubStr(Line,-1)!="`r`n" )
Line .= "`r`n"
Edit_Append(hEdit1, Line)
}
Edit_Append(hEdit, Txt) { ; Modified version by SKAN
Local ; Original by TheGood on 09-Apr-2010 @ autohotkey.com/board/topic/52441-/?p=328342
L := DllCall("SendMessage", "Ptr",hEdit, "UInt",0x0E, "Ptr",0 , "Ptr",0) ; WM_GETTEXTLENGTH
DllCall("SendMessage", "Ptr",hEdit, "UInt",0xB1, "Ptr",L , "Ptr",L) ; EM_SETSEL
DllCall("SendMessage", "Ptr",hEdit, "UInt",0xC2, "Ptr",0 , "Str",Txt) ; EM_REPLACESEL
}
;===================================================================================================
;RunCMD(CmdLine, WorkingDir:="", Codepage:="CP0", Fn:="RunCMD_Output") { ; RunCMD v0.94
RunCMD(CmdLine, WorkingDir:="", Codepage:="CP850", Fn:="RunCMD_Output") {
Local ; RunCMD v0.94 by SKAN on D34E/D37C @ autohotkey.com/boards/viewtopic.php?t=74647
Global A_Args ; Based on StdOutToVar.ahk by Sean @ autohotkey.com/board/topic/15455-stdouttovar
Fn := IsFunc(Fn) ? Func(Fn) : 0
, DllCall("CreatePipe", "PtrP",hPipeR:=0, "PtrP",hPipeW:=0, "Ptr",0, "Int",0)
, DllCall("SetHandleInformation", "Ptr",hPipeW, "Int",1, "Int",1)
, DllCall("SetNamedPipeHandleState","Ptr",hPipeR, "UIntP",PIPE_NOWAIT:=1, "Ptr",0, "Ptr",0)
, P8 := (A_PtrSize=8)
, VarSetCapacity(SI, P8 ? 104 : 68, 0) ; STARTUPINFO structure
, NumPut(P8 ? 104 : 68, SI) ; size of STARTUPINFO
, NumPut(STARTF_USESTDHANDLES:=0x100, SI, P8 ? 60 : 44,"UInt") ; dwFlags
, NumPut(hPipeW, SI, P8 ? 88 : 60) ; hStdOutput
, NumPut(hPipeW, SI, P8 ? 96 : 64) ; hStdError
, VarSetCapacity(PI, P8 ? 24 : 16) ; PROCESS_INFORMATION structure
If not DllCall("CreateProcess", "Ptr",0, "Str",CmdLine, "Ptr",0, "Int",0, "Int",True
,"Int",0x08000000 | DllCall("GetPriorityClass", "Ptr",-1, "UInt"), "Int",0
,"Ptr",WorkingDir ? &WorkingDir : 0, "Ptr",&SI, "Ptr",&PI)
Return Format("{1:}", "", ErrorLevel := -1
,DllCall("CloseHandle", "Ptr",hPipeW), DllCall("CloseHandle", "Ptr",hPipeR))
DllCall("CloseHandle", "Ptr",hPipeW)
, A_Args.RunCMD := { "PID": NumGet(PI, P8? 16 : 8, "UInt") }
, File := FileOpen(hPipeR, "h", Codepage)
, LineNum := 1, sOutput := ""
While (A_Args.RunCMD.PID + DllCall("Sleep", "Int",0))
and DllCall("PeekNamedPipe", "Ptr",hPipeR, "Ptr",0, "Int",0, "Ptr",0, "Ptr",0, "Ptr",0)
While A_Args.RunCMD.PID and (Line := File.ReadLine())
sOutput .= Fn ? Fn.Call(Line, LineNum++) : Line
A_Args.RunCMD.PID := 0
, hProcess := NumGet(PI, 0)
, hThread := NumGet(PI, A_PtrSize)
, DllCall("GetExitCodeProcess", "Ptr",hProcess, "PtrP",ExitCode:=0)
, DllCall("CloseHandle", "Ptr",hProcess)
, DllCall("CloseHandle", "Ptr",hThread)
, DllCall("CloseHandle", "Ptr",hPipeR)
, ErrorLevel := ExitCode
Return sOutput
}
;==================================================================================================
[/code]
von TEADRINKER (z.B. für schnelle Abläufe wie robocopy weniger geeignet , function AddOutputInGui evtl so anpassen dass er alle 5 Sekunden text an EDIT übermittelt (?) )
[code];- Hide command console when using RunWaitOne() example / from user teadrinker
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84266&sid=eff012cadb7a851b2c18f5f03b68408f
;----------------------------------------------
;- CREATED = 20201211 from user 'teadrinker'
;----------------------------------------------
cmdx:="ping autohotkey.com -n 3&&ver&&systeminfo" ;- <<<< here your command
;cmdx:="dir"
;============== GUI ===========
#warn
#noenv
Fileencoding,UTF-8
name1:="DOS_TEST"
global name1
e:=""
CPX:="cp" . DllCall("GetOEMCP", "UInt") ;- get CODEPAGE e.g. cp850
;CPX:="cp65001"
setworkingdir,%a_scriptdir%
Gui,1:default
Gui,1: -dpiscale
Gui,1:Color,Black,Black ; GUI black / EDIT is BLACK
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
;- maybe change fontsize depending scaling ( this is not calculated )
;============ GUISIZEx DPIx 4Kx 3840*2160 is 100% ============
if (wa=3840)
Gui,1:Font,s12 cYellow,Lucida Console
;============ GUISIZEx DPIx FHD 1920*1080 is 100% ============
else if (wa=1920)
Gui,1:Font,s10 cYellow,Lucida Console
else
Gui,1:Font,s8 cYellow,Lucida Console
;=============================================================
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*70)/xx,h:=(ha*60)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED1 ;- here the output
x:=(wa*1)/xx,y:=(ha*63)/xx,w:=(wa*65)/xx,h:=(ha*6)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED2,%cmdx% ;- add CMDx command above / or input command
x:=(wa*67)/xx,y:=(ha*63)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui, add, Edit, x%x% y%y% w%w% h%h% vED3, ;- ENDED
x:=(wa*67)/xx,y:=(ha*66)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui,add,button, x%x% y%y% w%w% h%h% gPrintx, PRINT
x:=(wa*2)/xx,y:=(ha*2)/xx,w:=(wa*75)/xx,h:=(ha*75)/xx
Gui, Show,x%x% y%y% w%w% h%h%,%name1%
gosub,a0 ;- remove this if add other commands below
GuiControl,1: Focus,ED2
return
;-------------------------
Guiclose:
Exitapp
esc::exitapp
;-------------------------
~$enter::
gosub,a0
return
;=========================================================
AddOutputInGui(output) {
Control, EditPaste, %output%`r`n, Edit1,%name1% ;- display output in 1st EDIT
}
;=========================================================
A0:
Gui,1:submit,nohide
Guicontrol,1:,ED3,...running
ed2a:="cmd /c " . ed2
xxc:=cmdret(ED2a, Func("AddOutputInGui"),CPX)
e .="`r`n===============================`r`n" . ed2 . " =`r`n-------------------------------`r`n" . xxc . "`r`n===============================`r`n"
e := RegExReplace(e, "((^)|\R)\h*(?=\R|$)(?(2)\R)") ;- remove empty lines
gosub,clear
;gosub,printx
return
;-------------------------
CLEAR:
Gui,1:submit,nohide
Guicontrol,1:,ED2,
Guicontrol,1:,ED3,ENDED
GuiControl,1: Focus,ED2
return
;-------------------------
printx:
f1=%a_desktop%\%a_now%_DOS_SCREEN_OUTPUT.txt
Gui,1:submit,nohide
if e<>
{
fileappend,%e%,%f1%,utf-8
run,%f1%
e:=""
}
return
;=========================================================
CmdRet(sCmd, callBackFuncObj := "", encoding := "CP0") ;- teadrinker https://www.autohotkey.com/boards/viewtopic.php?p=369467#p369467
{
static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
, STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
hPipeRead:=""
hPipeWrite:=""
sOutput:=""
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)
if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
, "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
{
DllCall("CloseHandle", "Ptr", hPipeRead)
DllCall("CloseHandle", "Ptr", hPipeWrite)
throw Exception("CreateProcess is failed")
}
DllCall("CloseHandle", "Ptr", hPipeWrite)
VarSetCapacity(sTemp, 4096), nSize := 0
while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
;sOutput .= stdOut := StrGet(&sTemp, nSize)
;sOutput .= stdOut := StrGet(&sTemp, nSize, CPX)
( callBackFuncObj && callBackFuncObj.Call(stdOut) )
}
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
DllCall("CloseHandle", "Ptr", hPipeRead)
Return sOutput
}
;================= END SCRIPT ========================================================================
[/code]