Modify

Opened 16 years ago

Closed 16 years ago

#473 closed Feature Request (Rejected)

Suggested modification to the internal RunWait command

Reported by: ryan2morrow@… Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description

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."

Attachments (0)

Change History (2)

comment:1 Changed 16 years ago by TicketCleanup

  • Milestone Future Release deleted
  • Version 3.2.12.1 deleted

Automatic ticket cleanup.

comment:2 Changed 16 years ago by Valik

  • Resolution set to Rejected
  • Status changed from new to closed

The way you do this is to use Run() with STDIO redirection. Then you use DllCall() with OpenProcess to open the process handle. You can then use ProcessWaitClose() to halt until the process exits. Finally you can use DllCall() and GetExitCodeProcesss to retrieve the exit code. And the StdXXXRead() functions will work, of course, since you have the PID.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.