【问题标题】:Netstat batch programNetstat 批处理程序
【发布时间】:2012-09-14 01:24:20
【问题描述】:

运行此批处理脚本时,结果始终相同。我相信我在语法中遗漏了一些东西。我错过了什么?

@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

【问题讨论】:

    标签: scripting batch-file


    【解决方案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. set 命令中为变量test 添加键/P
    3. 添加setlocal EnableDelayedExpansion。另见Batch File: Fails to Echo Variable Inside Loop

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 2014-03-17
      • 2017-04-09
      • 2016-05-24
      相关资源
      最近更新 更多