您可以使用ProcessExists函數來執行此操作。
下面是一個簡單的例子,一個超時選項:
MsgBox(64, "RunCmdWait", RunCmdWait("notepad.exe"))
Func RunCmdWait($sRuncmd, $iTimeout = 10000)
Local $iPid = Run(@ComSpec & " /c " & $sRuncmd, @ScriptDir, @SW_HIDE, 6)
Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
While 1
Sleep(250)
;Returns 0 when the process is closed
If ProcessExists($iPid) = 0 Then
SetError(0)
ExitLoop
EndIf
;Returns 1 on time out error
If TimerDiff($hTimer) >= $iTimeout Then
SetError(1)
ExitLoop
EndIf
WEnd
Return @error
EndFunc ;==>RunCmdWait
這裏是一個StdoutRead例如,如果你需要閱讀的輸出:
MsgBox(64, "StdoutRead", GetStdoutRead("dir"))
Func GetStdoutRead($sRuncmd)
Local $iPid = Run(@ComSpec & " /c " & $sRuncmd, @ScriptDir, @SW_HIDE, 6)
Local $sStdoutRead = ""
While ProcessExists($iPid)
$sStdoutRead &= StdoutRead($iPid)
WEnd
Return $sStdoutRead
EndFunc ;==>GetStdoutRead