Jump to content
Sign in to follow this  

STDOUT weirdness

Recommended Posts


I'm capturing stderr and stdout on a particular application and I'm not able to see the output of the command until the command has exited. However I am able to see the output of that commands child processes. If I run the command on the command line I am able to see all output in realtime. Is there any way to flush the console buffer or whatever is causing the text to hold up when redirection is occuring?

Share this post

Link to post
Share on other sites

thats a good question and something I have looked for before not been able to find the answer to. While I cannot answer your question I do know where it has been done before.

The following is taken from the Diskpart Library

;; Function     : __dpReadCommandOutput
;; Description  : Reads stdout until the next command prompt is seen or the process terminates
;; Parameters   : $pid      : [in]  running diskpart process identifier
;;                $output   : [out] contents of stdout
;; Returns      : Success   : 1
;;                Failure   : 0
;;                @ERROR    : 0  = Success
;;                          : 1  = Failure
;;                @EXTENDED : 2  = $_DP_ErrorCode_InvalidProcessID
;;                          : 3  = $_DP_ErrorCode_UnexpectedTermination
;;                          : 4  = $_DP_ErrorCode_StdoutStreamError
Func __dpReadCommandOutput( $pid, ByRef $output )
    If Not ProcessExists( $pid ) Then Return __dpSetError( 1, $_DP_ErrorCode_InvalidProcessID, 0 )

    $output = ""
    While ProcessExists( $pid )
        ConsoleWrite("In __dpReadCommandOutput while loop" & @LF)
        Local $_peek = StdoutRead( $pid, 0, True )
        If @error Then Return __dpSetError( 1, $_DP_ErrorCode_StdoutStreamError, 0 )
        ConsoleWrite("Peek is " & $_peek & @LF)    
        If $_peek > 0 Then
            $output &= StdoutRead( $pid, $_peek )
            ConsoleWrite("Peek is greater than 0 and output is " & $output & @LF)  
            If @error Then Return __dpSetError( 1, $_DP_ErrorCode_StdoutStreamError, 0 )
        ; We loop until the process terminates or we see the next prompt
        If StringRegExp( $output, "(?i)diskpart>", 0 ) Then Return __dpSetError( 0, 0, 1 )
    ; its up to the calling code to determine if this was really unexpected or not
    ; since we don't make any assumptions about the commands being issued
    Return __dpSetError( 1, $_DP_ErrorCode_UnexpectedTermination, 0 )

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this