• 关于Windows下的批处理如何模拟Sleep


    好好的批处理,居然没有正式的Sleep可供调用。有时候,确实感到很无趣。

    1. 方法1:  

    ping 1.1.1.1来模拟

    好不容易从stackoverflow上找到一个答案(称之为答案,是因为它被人标注为answer),是这么实现的:
    ping 1.1.1.1 -n 1 -w 60000 > nul
    这个表示,会sleep 60秒钟。

    果真如此吗? 它要基于一个假设:1.1.1.1永远不会被目标机器ping通。但我却碰到了灵异事件,在某台测试机上,直接能ping通:

    Pinging 1.1.1.1 with 32 bytes of data:
    Reply from 1.1.1.1: bytes=32 time<1ms TTL=60
    Reply from 1.1.1.1: bytes=32 time<1ms TTL=60
    Reply from 1.1.1.1: bytes=32 time=6ms TTL=60
    Reply from 1.1.1.1: bytes=32 time<1ms TTL=60


    Ping statistics for 1.1.1.1:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum = 6ms, Average = 1ms

    所以,这个方法是靠不住的。


    2. 依然使用ping来模拟,

    请看下边的bat:

    @echo off
    
    
    echo "emulate sleep......"
    call :wait_ext1 60
    echo "60 seconds waited...."
    goto :eof
    
    :wait_ext1
    @ping 127.0.0.1 -n 2 -w 1000 > nul
    @ping 127.0.0.1 -n %1% -w 1000> nul
    


    这个就表示要sleep大概60秒钟。

    当然,你也可以把wait_ext1那部分重命名一个单独的批处理进行调用。

    3. 似乎2003还有一个resource kit包下载,里边就有sleep.exe

    (为何不发布出来呢?)
    http://malektips.com/xp_dos_0002.html

    有时候真的是痛恨Windows下的批处理.

     
  • 相关阅读:
    CodeForces 587A
    矩阵快速幂模板
    LCA模板
    Codeforces Round #226 (Div. 2 )
    Codeforces Round #225 (Div. 2)
    SGU132
    SRM 599 DIV 2
    POJ1038
    SGU223
    POJ1185
  • 原文地址:https://www.cnblogs.com/fuhaots2009/p/3503465.html
Copyright © 2020-2023  润新知