Modify

#3722 closed Bug (Fixed)

StdoutRead example is incorrectly parsing input and outputs incomplete information

Reported by: anonymous Owned by: Jos
Milestone: 3.3.15.1 Component: Documentation
Version: 3.3.14.2 Severity: None
Keywords: StdoutRead Cc:

Description

The current example of StdoutRead is parsing the input of the Run-command wrong.
It's this block in particular.

; Use StringSplit to split the output of StdoutRead to an array. All carriage returns (@CRLF) are stripped and @CRLF (line feed) is used as the delimiter.
Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@CRLF)), @CRLF)

The comment is wrong too. All carriage returns are stripped but carriage returns are @CRs not @CRLFs.
@CRLF (line feed) is also wrong.

If you break up the commands line by line it looks like this:

Local $sStrippedCR = StringStripCR($sOutput)

Local $sTrimmed = StringTrimRight($sStrippedCR, StringLen(@CRLF))

Local $aArray = StringSplit($sTrimmed, @CRLF)

What happens?

L 1: All @CRs are removed from the string
L 2: 2 characters are removed from the right side of the string although only @LFs are left therefore resulting in cutting away one character from the last array entry (which gets created now)
L 3: Split the array with @CRLF. Since no third parameter is provided $STR_CHRSPLIT is provided which results in a still-decently-split array.

The error probably wasn't noticed due to $STR_CHRSPLIT still splitting the array (with @CR and @LF) and the very last character missing of the array entry which you only see if you pay attention.

I don't know who came up with the wrong line but he must have been on drugs or something.
Windows (AutoIt doesn't run natively on other operating systems) uses @CRLF by standard and we are parsing from a windows command anyway.
Instead of complicating the whole operation with StringStripCR we could've made it so much easier:

How to fix?

Local $aArray = StringSplit(StringTrimRight($sOutput, StringLen(@CRLF)), @CRLF, $STR_ENTIRESPLIT)

Attachments (0)

Change History (3)

in reply to:  description comment:1 by Jos, on Jun 27, 2019 at 9:41:40 AM

Replying to anonymous:

I don't know who came up with the wrong line but he must have been on drugs or something.

Why did you feel the urge to make this statement? When you want to be taken seriously you could try the professional communication approach.

I checked the commits for this file and see that it was changed in Revision 7904 (15/7/2013) which indeed should be reverted.

Jos

Version 0, edited on Jun 27, 2019 at 9:41:40 AM by Jos (next)

comment:2 by anonymous, on Jun 27, 2019 at 11:06:07 AM

I was just making fun of that line because it seems hilariously stupid and complicating to me.
Granted I've made stupid mistakes like these too. No bad intention of course :)

About that console thing, you're probably right. But I was going with the original settings since there are no specific checks for every single thing that can be changed within AutoIt otherwise the help-file-examples would explode with if-conditions.

Anyway, hopefully it will be fixed soon so the example provides a good example again.
Thanks for working on it!

comment:3 by Jos, on Jun 27, 2019 at 2:17:50 PM

Milestone: 3.3.15.1
Owner: set to Jos
Resolution: Fixed
Status: newclosed

Fixed by revision [12218] in version: 3.3.15.1

Modify Ticket

Action
as closed The owner will remain Jos.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.