0

このバッチスクリプトを実行すると、結果は常に同じになります。構文に何かが欠けていると思います。私は何が欠けていますか?

@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
4

1 に答える 1

1
@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

必要なもの:

  1. %変数で削除test
  2. 変数のコマンドにキー/Pを追加settest
  3. 追加しsetlocal EnableDelayedExpansionます。バッチファイル:ループ内の変数のエコーに失敗するも参照してください。
于 2012-09-14T02:24:09.020 に答える