Results 1 to 4 of 4
  1. #1
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts
    For many years at work I have been using a BATch file which sends a WakeOnLAN magic packet over the network to wake up a specific (XP Pro) PC, then loops round PINGing the PC until it responds. The loop includes

    set "tm=%time%" & echo !tm: =0!

    to echo the current time (to two decimal places of seconds), and on my work domain these failed PINGs consistently take exactly 4.50 seconds.

    Trying the same recently on my home workgroup (XP Pro and Home, and Windows 7 Pro), I was surprised to find that the time interval between failed PINGs varied and was about 3.7 +/- 0.3 seconds.

    Has anyone else noticed this behavioural disparity? Or explain the difference?
    BATcher

    Time prevents everything happening all at once...

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,203
    Thanks
    49
    Thanked 989 Times in 919 Posts
    "echo !tm: =0!"

    Please explain?

    cheers, Paul

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Try running (before 10:00!)

    Code:
    @echo off
    setlocal enabledelayedexpansion
    for /l %%a in (1,1,5) do (
      echo %time: =0%
      echo !time: =0!
      ping -n 2 127.0.0.1 > nul & echo.
    )
    endlocal
    and you'll see the effect of 'delayed expansion'. When inside a loop, the value of %time% is evaluated when the BATch file is started; however the value of !time! is evaluated at the time the statement is executed, in other words the expansion of the variable is delayed.

    If your question was about the character substitution in %time: =0% this simply changes a time like " 1:23:45.67" to "01:23:45.67", so adds the leading zero in front of the hours field.
    BATcher

    Time prevents everything happening all at once...

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,203
    Thanks
    49
    Thanked 989 Times in 919 Posts
    Leading 0s, who'd have thought it?!

    cheers, Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •