vbscript - Strange Variable assignments

Answered vbscript - Strange Variable assignments

  • Wednesday, January 30, 2013 4:58 PM
     
     

    Not sure where its happening but I'm getting some really strange output from variables when trying to combine.  

    Here is the code

    vAdpDesc = Adapters.Description
    vAdpMac = Adapters.MACAddress
    strDebugMSG = strDebugMSG & "Adapter Description:" & vAdpDesc & " Adapter MAC:" & vAdpMac & vbCrLf
    vTempOut = vSysDrive & "\temp\adapter_" & replace(vAdpMac,":","") & "_out.txt"
    vCMD = "cmd /c " & """" & vSysDrive & "\Program Files\Broadcom\BACS\BACScli.exe"" -t NDIS -f mac -i " & replace(vAdpMac,":","") & " info > " & vTempOut
    strDebugMSG = strDebugMSG & "CMD:" & vCMD & vbCrLf
    WshShell.Run vCMD,0,True
    vDuplex = "N/A"
    vSpeed = "N/A"
    If objFSO.FileExists (vTempOut) Then
    Set objNIC=objFSO.OpenTextFile (vTempOut,1)
            Do Until objNIC.AtEndOfStream
             vLine = Trim(objNIC.Readline)
                    arLine = split(vLine,":")
                    If Instr(vLine,"Duplex") > 0 Then
                     vDuplex = Trim(arLine(2))
                            strDebugMSG = strDebugMSG & "Duplex Line:" & vLine & vbCrLf
                            strDebugMSG = strDebugMSG & "Duplex:" & vDuplex & vbCrLf
                    End If
                    If Instr(vLine,"Speed") > 0 Then
                           vSpeed = Trim(arLine(2))
                           strDebugMSG = strDebugMSG & "Speed Line:" & vLine & vbCrLf
                           strDebugMSG = strDebugMSG & "Speed:" & vSpeed & vbCrLf
                    End If
           Loop
    End If
    wscript.echo vAdpMac & "," & vSpeed
    wscript.echo vAdpMac & "," & vDuplex

    wscript.echo vAdpMac & "," & vSpeed & "," & vDuplex

    Here is the output I am seeing

    00:1E:4F:3A:36:D8,1000
    00:1E:4F:3A:36:D8,Full

    ,Full      :36:D8,1000

    00:1E:4F:3A:36:D6,1000
    00:1E:4F:3A:36:D6,Full

    ,Full      :36:D6,1000

    00:1E:4F:3A:36:D8,1000
    00:1E:4F:3A:36:D8,Full
    ,Full      :36:D8,1000

    As you can see on the first 2 echos I'm seeing exactly what I would expect from all the variables but when we get to the last echo it goes all strange and honestly I don't know why since its the next line in the code after seeing they were all ok.  You can see the speed and duplex swap and then the mac is being added to the speed and cutting it off and not showing anything in the mac location at all.

    Thanks in advance

    --Todd

All Replies

  • Wednesday, January 30, 2013 8:11 PM
    Moderator
     
     Answered

    That's usually the result of a line of text that contains a carriage return without a linefeed.  It would therefore appear to be because of the BACScli.exe procedure.  It might be possible to fix it with a pipe through the FIND utility ...

      ...\BACScli.exe ... & "info | find /v """" > " ...

    If that doesn't fix it, you will need to Replace(string, vbCR, vbCRLF) and then parse the line again at the newline.


    Tom Lavedas

    • Marked As Answer by twooly Thursday, January 31, 2013 11:21 AM
    •  
  • Thursday, January 31, 2013 11:21 AM
     
     

    That was it, did a replace on vbCR on the new line read.

    Thank you very much.