このバッチスクリプトを実行すると、結果は常に同じになります。構文に何かが欠けていると思います。私は何が欠けていますか?
@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
このバッチスクリプトを実行すると、結果は常に同じになります。構文に何かが欠けていると思います。私は何が欠けていますか?
@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
@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
必要なもの:
%
変数で削除test
/P
を追加set
test
setlocal EnableDelayedExpansion
ます。バッチファイル:ループ内の変数のエコーに失敗するも参照してください。