-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathStdOutToVar (2).ahk
40 lines (36 loc) · 1.79 KB
/
StdOutToVar (2).ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
StdOutToVar(cmd) {
DllCall("CreatePipe", "PtrP", hReadPipe, "PtrP", hWritePipe, "Ptr", 0, "UInt", 0)
DllCall("SetHandleInformation", "Ptr", hWritePipe, "UInt", 1, "UInt", 1)
VarSetCapacity(PROCESS_INFORMATION, (A_PtrSize == 4 ? 16 : 24), 0) ; http://goo.gl/dymEhJ
cbSize := VarSetCapacity(STARTUPINFO, (A_PtrSize == 4 ? 68 : 104), 0) ; http://goo.gl/QiHqq9
NumPut(cbSize, STARTUPINFO, 0, "UInt") ; cbSize
NumPut(0x100, STARTUPINFO, (A_PtrSize == 4 ? 44 : 60), "UInt") ; dwFlags
NumPut(hWritePipe, STARTUPINFO, (A_PtrSize == 4 ? 60 : 88), "Ptr") ; hStdOutput
NumPut(hWritePipe, STARTUPINFO, (A_PtrSize == 4 ? 64 : 96), "Ptr") ; hStdError
if !DllCall(
(Join Q C
"CreateProcess", ; http://goo.gl/9y0gw
"Ptr", 0, ; lpApplicationName
"Ptr", &cmd, ; lpCommandLine
"Ptr", 0, ; lpProcessAttributes
"Ptr", 0, ; lpThreadAttributes
"UInt", true, ; bInheritHandles
"UInt", 0x08000000, ; dwCreationFlags
"Ptr", 0, ; lpEnvironment
"Ptr", 0, ; lpCurrentDirectory
"Ptr", &STARTUPINFO, ; lpStartupInfo
"Ptr", &PROCESS_INFORMATION ; lpProcessInformation
)) {
DllCall("CloseHandle", "Ptr", hWritePipe)
DllCall("CloseHandle", "Ptr", hReadPipe)
return ""
}
DllCall("CloseHandle", "Ptr", hWritePipe)
VarSetCapacity(buffer, 4096, 0)
while DllCall("ReadFile", "Ptr", hReadPipe, "Ptr", &buffer, "UInt", 4096, "UIntP", dwRead, "Ptr", 0)
sOutput .= StrGet(&buffer, dwRead, "CP0")
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, 0)) ; hProcess
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize)) ; hThread
DllCall("CloseHandle", "Ptr", hReadPipe)
return sOutput
}