Eambo Posted November 9, 2017 Posted November 9, 2017 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? #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)
Floops Posted November 10, 2017 Posted November 10, 2017 Have you tried $STDERR_MERGED instead of $STDOUT_CHILD ?
rootx Posted November 10, 2017 Posted November 10, 2017 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
Floops Posted November 10, 2017 Posted November 10, 2017 @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!
Eambo Posted November 10, 2017 Author Posted November 10, 2017 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now