Jump to content
Sign in to follow this  
Eambo

Issues capturing StdOutRead

Recommended Posts

Eambo

Hey guys!

 

This is almost definitely just me doing something very silly, but as you can see in the screenshot below:

 

- Super basic code
- Returns "curl: (6) Couldn't resolve host 'TEST'
- Trying to get this into a string
- Stdout Read is returning empty it would seem.

Would anyone be able to advise where I'm going wrong here? 

otNq7fQ.png

 

 

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3> ; Required for _ArrayDisplay only.

$err6="(6) Couldn't resolve host"

   $iPID = Run("curl.exe -X POST TEST","", @SW_HIDE, $STDOUT_CHILD)

   Local $sOutput = ""
    While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
            MsgBox(0,0,@error)
            ExitLoop
        EndIf
    WEnd
    MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

 

Share this post


Link to post
Share on other sites
Floops

Have you tried $STDERR_MERGED instead of $STDOUT_CHILD ?

Share this post


Link to post
Share on other sites
rootx

Voilà

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3> ; Required for _ArrayDisplay only.


$_Pid = Run ("curl.exe https://www.autoitscript.com", '', @SW_HIDE, $STDERR_MERGED )

Dim $_StderrRead='', $_StdoutRead='', $_StdReadAll='', $_ProcessTimerInit = TimerInit ( )

While ProcessExists ( $_Pid )
    $_StderrRead = StderrRead ( $_Pid )
    If Not @error And $_StderrRead <> '' Then
        ConsoleWrite ( "STDERR read : " & $_StderrRead & @Crlf )
    EndIf
    $_StdoutRead = StdoutRead ( $_Pid )
    If Not @error And $_StdoutRead <> '' Then
        ConsoleWrite ( "STDOUT read : " & $_StdoutRead & @Crlf )
    EndIf
    If Round ( TimerDiff ( $_ProcessTimerInit ) / 1000 ) > 3 And $_StdReadAll ='' Then
        If ProcessExists ( $_Pid ) Then ProcessClose ( $_Pid )
        ExitLoop
    EndIf
Wend

 

Share this post


Link to post
Share on other sites
Floops

@rootx Good example but wouldn't using BitOR($STDOUT_CHILD, $STDERR_CHILD) be better here? Of course you want to read both channels but you don't want them to be combined. Correct me if I'm wrong though!

Share this post


Link to post
Share on other sites
Eambo

Thank you guys! I meant to respond earlier but you beat me to it, however yeah I realised later this was STDERR_CHILD being missing and not grabbign the StderrRead.

Sorted, thank you for your assistance on my derpiness! ^_^

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.