Reputation: 4736
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
Upvotes: 0
Views: 357
Reputation: 84
If netstatOutput = "" Then WScript.Echo "OK: port is free" Else WScript.Echo "ERROR: port is in use" End If
Upvotes: 0
Reputation: 35260
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.
Upvotes: 2