Reputation: 317
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
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:
%
at variable test
/P
in set
command for variable test
setlocal EnableDelayedExpansion
. See also Batch File: Fails to Echo Variable Inside LoopUpvotes: 1