RunCmd(CmdLine, WorkingDir:="", Cp:="CP0") { ; Thanks Sean! SKAN on D34E @ tiny.cc/runcmd
Local P8 := (A_PtrSize=8), pWorkingDir := (WorkingDir ? &WorkingDir : 0)
Local SI, PI, hPipeR:=0, hPipeW:=0, Buff, sOutput:="", ExitCode:=0, hProcess, hThread
DllCall("CreatePipe", "PtrP",hPipeR, "PtrP",hPipeW, "Ptr",0, "UInt",0)
, DllCall("SetHandleInformation", "Ptr",hPipeW, "UInt",1, "UInt",1)
VarSetCapacity(SI, P8? 104:68,0), NumPut(P8? 104:68, SI)
, NumPut(0x100, SI, P8? 60:44,"UInt"), NumPut(hPipeW, SI, P8? 88:60)
, NumPut(hPipeW, SI, P8? 96:64)
, VarSetCapacity(PI, P8? 24:16)
If not DllCall("CreateProcess", "Ptr",0, "Str",CmdLine, "Ptr",0, "UInt",0, "UInt",True
, "UInt",0x08000000 | DllCall("GetPriorityClass", "Ptr",-1,"UInt"), "UInt",0
, "Ptr",pWorkingDir, "Ptr",&SI, "Ptr",&PI )
Return Format( "{1:}", ""
, DllCall("CloseHandle", "Ptr",hPipeW)
, DllCall("CloseHandle", "Ptr",hPipeR)
, ErrorLevel := -1 )
DllCall( "CloseHandle", "Ptr",hPipeW)
, VarSetCapacity(Buff, 4096, 0), nSz:=0
While DllCall("ReadFile", "Ptr",hPipeR, "Ptr",&Buff, "UInt",4094, "PtrP",nSz, "UInt",0)
sOutput .= StrGet(&Buff, nSz, Cp)
hProcess := NumGet(PI, 0), hThread := NumGet(PI,4)
, DllCall("GetExitCodeProcess", "Ptr",hProcess, "PtrP",ExitCode)
, DllCall("CloseHandle", "Ptr",hProcess), DllCall("CloseHandle", "Ptr",hThread)
, DllCall("CloseHandle", "Ptr",hPipeR), ErrorLevel := ExitCode
Return sOutput
}
RunCmd( A_Comspec . " /c Dir *.* /s", A_AhkPath . "\..\")
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
老兄这个怎么能方便执行cmd命令呢
例如
MsgBox,% RunCmd(“ipconfig”)