﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
473	Suggested modification to the internal RunWait command	ryan2morrow@…		"I'd like to suggest adding StdIn and StdErr to the RunWait command.  As it is, Run allows you to attach to these to capture the actual result of, say, a DOS command, but doesn't allow capturing the exitcode of that command.  RunWait allows capturing the exitcode of the command, but not the output of the command.  Perhaps make RunWait return the PID of the command it ran and set the @extended to the exitcode it returned instead, although this would break a lot of code.  Or maybe add an option to RunWait (like a mode) to tell it to act this way instead of the current way.

{{{
RunWait( ""filename"" [, ""workingdir"" [, flag [, mode]]] )
}}}

Where mode is:

0 = (Default) Return the exitcode of the command, nothing else, like it does now to avoid breaking code.

1 = Return the PID of the command, @extended as the exitcode, allow StdOutRead and StdErrRead to get the output of the command.

Adding StdIn and StdErr would allow you to do something like the following to gain more detail about the command you ran:

{{{
;===============================================================================
;
; Description:      Executes a DOS command in a hidden command window.
; Syntax:           _RunDOS( $sCommand )
; Parameter(s):     $sCommand - Command to execute
;                   $nFlag - 0=Classic mode, return only the exitcode
;                            1=Return StdOut, @extended=exitcode
;                            2=Return StdErr, @extended=exitcode
;                      (1+2=)3=Return both (StdOut & @CRLF & StdErr), @extended=exitcode
; Requirement(s):   None
; Return Value(s):  $nFlag is invalid - Return -1
;                   $nFlag=0 (Classic mode - Default) - Return the only the exitcode of the command
;                   $nFlag=1 - Return StdOut stream of the command, @extended=exitcode
;                   $nFlag=2 - Return StdErr stream of the command, @extended=exitcode
;                   $nFlag=3 - Return StdOut & @CRLF & StdOut, @extended=exitcode
; Author(s):        Jeremy Landes <jlandes at landeserve dot com>
; Note(s):          None
;
;===============================================================================
Func _RunDOS($sCommand, $nFlag=0)
	Local $nPID, $nResult, $sResult="""", $sStdOut="""", $sStdErr=""""
	
	If $nFlag < 0 or $nFlag > 3 Then ; Invalid flag setting
		Return SetError(0, 0, -1)
	Else
		$nResult = RunWait(@ComSpec & "" /C "" & $sCommand, @ScriptDir, @SW_HIDE, $nFlag)
		If $nFlag = 0 Then ; Classic mode
			Return SetError(@error, @extended, $nResult)
		Else
			$nPID = $nResult
			$nResult = @error
			If BitAND($nFlag, 1) Then $sStdOut = StdoutRead($nPID) ; Attached StdOut
			If BitAND($nFlag, 2) Then $sStdErr = StderrRead($nPID) ; Attached StdErr
			$sResult = $sStdOut & @CRLF & $sStdErr
			If $nFlag = 1 ; Attached StdOut only
				Return SetError($nResult, 0, $sStdOut)
			ElseIf $nFlag = 2 ; Attached StdErr only
				Return SetError($nResult, 0, $sStdErr)
			Else ; =3
				Return SetError($nResult, 0, $sResult)
			EndIf
		EndIf
	EndIf
EndFunc   ;==>_RunDOS

}}}

So, for example, if you ran a rename command RunWait(@comspec & "" /c ren this.txt that.txt"", """", @SW_HIDE, 3), you could see not only that the exitcode is non-zero (as you can today), but you could also capture the StdOutRead() and see that the error was ""Access is denied."""	Feature Request	closed		AutoIt		None	Rejected		
