Jump to content

STDOUTREAD [Solved]


ken82m
 Share

Recommended Posts

I've only had to use STDOUTREAD once or twice and not in quite a while.

Can someone please tell me why the code below doesn't return anything.

I'm at a loss as to why the example works but not this.

Thanks,

Kenny

My Test (Does Not Work)-

The only difference is the location of the MSGBOX's but they return nothing.

Local $foo = Run(@ComSpec & ' /c dir', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0, "STDOUT read:", $line)


While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0, "STDERR read:", $line)

MsgBox(0, "Debug", "Exiting...")

Example in Help File (Works)-

I first get a blank MSGBOX from STDOUTREAD and then another from STDOUTREAD containing the data.

Local $foo = Run(@ComSpec & ' /c dir', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0, "STDOUT read:", $line)


While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0, "STDERR read:", $line)

MsgBox(0, "Debug", "Exiting...")
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I got it, looked up a UDF and an old script I wrote.

The example might need a little revising in the help file.

-Kenny

Local $foo = Run(@ComSpec & ' /c dir', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
Local $line2
    
While ProcessExists($foo)
   $line = StdoutRead($foo, True)
   $line2 = StderrRead($foo, True)
WEnd
MsgBox(4096,"StdoutRead", $line)
MsgBox(4096,"StderrRead", $line2)
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

  • 2 weeks later...

Hello, I'm looking in the same direction and was puzzled by the help example.

Do I understand well your suggested code if I say that the second parameter (TRUE) in StdoutRead is peek parameter?

While ProcessExists($foo)
   $line = StdoutRead($foo, True)
   $line2 = StderrRead($foo, True)
WEnd

In such circumstances, the code should not wait until end of child process but poll stdout for new char.

I cannont obtain such a behaviour. My code (exemple below) is supposed to receive output from child while child is running, enabling to control the progress and showing it in a progress bar. Unfortunately, the code waits until child exits and prevents me from monitoring the progress. I get stdout only once when child exits. Do you know why?

Local $Button_1,  $msg
    GUICreate("My GUI Button"); will create a dialog box that when displayed is centered
    $Button_1 = GUICtrlCreateButton("Run .EXE", 10, 30, 100)
    
    $prg=GUICtrlCreateProgress(10,60,200,20)
    $in=GUICtrlCreateInput("",10,90,200,20)

    GUISetState()     
    $tst=0
   ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                $tst=Run('test.exe','',0,$STDOUT_CHILD)   
        EndSelect
        if $tst<>0 Then

            While ProcessExists($tst)
                $line = StdoutRead($tst, True)
                GUICtrlSetData($prg,strlen($line))
            WEnd

        EndIf 
    WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...