0

I want to check if the output of the netstat command I run in vbscript is empty or not. The below is not working as the port is not in use but it skips past that fact and goes to ERROR (else).

I think it is due to the IsNULL? I could not find what else I could use in vbscript?

Set netStatRun = objShell.Exec("cmd /C ""netStat -ano |find ""1002""""")
        netStatOutPut = netStatRun.StdOut.ReadLine
        WScript.Echo "The value is: " & netStatOutPut

            If IsNull(netStatOutPut) Then
                WScript.Echo "The port is free"
            Else
                WScript.Echo "ERROR! Port is use"
            End If

OUTPUT:

The value is:
ERROR! Port is use

2 Answers 2

2

Instead of using IsNull(netStatOutPut) try using Len(netStatOutPut) = 0

If Len(netStatOutPut) = 0 Then
    WScript.Echo "The port is free"
Else
    WScript.Echo "ERROR! Port is use"
End If

You can't use IsNull to determine that a string is a zero-length string.

Sign up to request clarification or add additional context in comments.

Comments

0
If netstatOutput = "" Then
    WScript.Echo "OK: port is free"
Else
    WScript.Echo "ERROR: port is in use"
End If

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.