Modify

Opened 2 months ago

Closed 2 months ago

#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)

comment:1 in reply to: ↑ description Changed 2 months ago by Jos

Replying to anonymous:

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

Humans make mistakes ... right?

I checked the commits for this file and see that it was changed in Revision 7904 (15/7/2013) which indeed should be reverted.
As to your fix: One have to assume that some console applications do not always return @CRLF, but only use @LF, hence was chosen to strip the @CR character and also support programs that only have a @LF as EOL.

Jos

Last edited 2 months ago by Jos (previous) (diff)

comment:2 Changed 2 months ago by anonymous

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 Changed 2 months ago by Jos

  • Milestone set to 3.3.15.1
  • Owner set to Jos
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [12218] in version: 3.3.15.1

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jos.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.