0

I made a parser for my internship. It has all been working out well except for the fact that I ran into a very strange bug that has a huge effect on a part of the error message parsing.

I grab a line with select-string and assign it to the variable $excluded. Then I narrow the search to take out ignorable error codes that are due to the real errors. This is where it gets weird. If there are multiple error lines that select-string grabs, it makes each line a part of the array (I think that is how it works) so that my parsing out the error message works fine. However, if there is only one error line, it takes that error line and splices every single digit to make a one column, many row array. My parser takes each row individually and sorts out the error code (which it does perfectly if it is is multiple errors).

Here is the text grab part of my code so you can get an idea of what I am explaining.

#If there is "EXCLUDED" then select those lines and extract the device code from them
$excluded = (Select-String -Path $report -Pattern EXCLUDED | Select-String -Pattern $eliminations -NotMatch).Line

This is the part of the text file I am grabbing (example) if it doesn't work.

027:01:1e:01:06 SRB:Phy00 EXCLUDED FROM TEST - GOERR IS SET

now I took that line, and I copied/pasted it and changed the first 3 digit number (device code)

027:01:1e:01:06 SRB:Phy00 EXCLUDED FROM TEST - GOERR IS SET
028:01:1e:01:06 SRB:Phy00 EXCLUDED FROM TEST - GOERR IS SET

The second set of text (How it is supposed to look)

$excluded[0] = 027:01:1e:01:06 SRB:Phy00 EXCLUDED FROM TEST - GOERR IS SET
$excluded[1] = 028:01:1e:01:06 SRB:Phy00 EXCLUDED FROM TEST - GOERR IS SET

However, for the single error line, this is what comes out

$excluded[0] = 0
$excluded[1] = 2
$excluded[2] = 7

I am baffled as to why this happens. I have tested it with multiple error codes, frequencies, and this happens with all error codes where only one line is passed to $excluded.

Can anyone tell me why this is?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
hawkeye315
  • 15
  • 4

0 Answers0