JRR
JRR

Reputation: 317

Netstat batch program

When running this batch script the results are always the same. I believe I am missing something in the syntax. What am I missing?

@echo off
netstat -an | find /C "LIST" > tmpFile
set test=<tmpFile
del tmpFile
set max=6
IF !%test! GTR !max! echo Greater than X
IF !%test! LEQ !max! echo Less than X
PAUSE
:EOF

Upvotes: 0

Views: 4599

Answers (1)

Lex
Lex

Reputation: 319

@echo off
setlocal EnableDelayedExpansion

netstat -an | find /C "LIST" > tmpFile
set /P test=<tmpFile
del tmpFile
set max=20
IF !test! GTR !max! echo Greater than X
IF !test! LEQ !max! echo Less than X
PAUSE
:EOF

You need:

  1. Remove % at variable test
  2. Add key /P in set command for variable test
  3. Add setlocal EnableDelayedExpansion. See also Batch File: Fails to Echo Variable Inside Loop

Upvotes: 1

Related Questions