We're aware that some users are experiencing technical issues which the team are working to resolve. See the Community Noticeboard for more info. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Extended characters in batch files?

Options
2»

Comments

  • John_Gray
    John_Gray Posts: 5,843 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Photogenic
    esuhl wrote: »
    Ah, so I was right. How reliable is the 1-second interval? Is it documented as such on all Windows versions, or does it depend on other things?
    Well, PING started out on Unix, AFAICR!
    I have always found it to be pretty accurate, assuming there's enough CPU around to service it.

    Try, in a BATch file:
    echo %time%
    echo %time%
    :: difference is time which echo takes (less than 1 centisecond?)
    ping -4 -n 1201 127.0.0.1 > nul
    echo %time%
    :: difference should be 1200 seconds = 20 minutes exactly
    :: subtract the "time taken by echo" for slightly more accuracy!


    Obviously you can play with the numbers to suit!
  • esuhl
    esuhl Posts: 9,409 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    John_Gray wrote: »
    Well, PING started out on Unix, AFAICR!
    I have always found it to be pretty accurate, assuming there's enough CPU around to service it.

    I'm familiar with the ping command (just not all its options!). The help entry for ping on my Windows system says this:
    Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
                [-r count] [-s count] [[-j host-list] | [-k host-list]]
                [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name
    
    Options:
    ...
        -n count       Number of echo requests to send.
    ...
    

    So "-n 1201" should just send 1,201 echo requests. It doesn't say that these are sent every second... or is that something that can safely be assumed? What defines the one-second interval?

    Hmmm... I just gave your script a quick go (over ten minutes, rather than twenty) and it is pretty accurate. The first two time echoes are identical to the 1/100th of a second. Then after the "ten minute" delay, the time appears as 10 minutes and 18/100ths of a second. Cool.
  • Strider590
    Strider590 Posts: 11,874 Forumite
    edited 10 February 2017 at 4:18PM
    John_Gray wrote: »
    Timeout?
    Real BATch writers use
    PING -4 -n 11 127.0.0.1 > nul
    (for a 10-second delay)!


    That's just a dirty hack.....

    The problem with using ping.exe, is that if the network adaptor changes state for any reason, it causes ping.exe to throw up an error without running the expected delay at all.

    "Real batch writers" use a separate batch file which takes an input variable and writes it to a VBS script (which uses the "sleep" command to give exact time delays) and then runs that script before returning to the original file.

    You could of course be lazy, create a .vbs file 1 second delay and then run it multiple times.

    With a delay script created all I need is:

    set dly=C:\dly.bat

    At the top of every batch file and then

    %dly% 1

    for 1 second

    %dly% 10

    for 10 seconds


    But that's all academic, the fact remains that "timeout" is Win7 onwards.
    “I may not agree with you, but I will defend to the death your right to make an a** of yourself.”

    <><><><><><><><><<><><><><><><><><><><><><> Don't forget to like and subscribe \/ \/ \/
  • esuhl
    esuhl Posts: 9,409 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    Strider590 wrote: »
    "Real batch writers" use a separate batch file which takes an input variable and writes it to a VBS script (which uses the "sleep" command to give exact time delays) and then runs that script before returning to the original file.

    OMG! This is getting awesomely geeky! :D

    You mentioning VBS script makes me think that, maybe, batch files are just too simple for the kind of polished effect that I want. Years ago I wrote moderately simple code in Visual Basic 6.0 and VBA, so maybe I should use VBScript instead...? I'll look into that.

    I don't suppose you know of any good tutorials?
    Strider590 wrote: »
    But that's all academic, the fact remains that "timeout" is Win7 onwards.

    Totally academic (such is my interest!). But I think "timeout" is Vista onwards...

    https://technet.microsoft.com/en-us/library/cc754891(v=ws.11).aspx
  • Strider590
    Strider590 Posts: 11,874 Forumite
    esuhl wrote: »
    Totally academic (such is my interest!). But I think "timeout" is Vista onwards...

    https://technet.microsoft.com/en-us/library/cc754891(v=ws.11).aspx


    Vista was tripe and as such doesn't count as an OS :p same for Win8 :rotfl:
    “I may not agree with you, but I will defend to the death your right to make an a** of yourself.”

    <><><><><><><><><<><><><><><><><><><><><><> Don't forget to like and subscribe \/ \/ \/
  • paddyrg
    paddyrg Posts: 13,543 Forumite
    esuhl wrote: »
    OMG! This is getting awesomely geeky! :D...maybe I should use VBScript instead...? I'll look into that...

    Actually you probably want powershell instead (and probably already have it - powershell.exe).
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 350.9K Banking & Borrowing
  • 253.1K Reduce Debt & Boost Income
  • 453.5K Spending & Discounts
  • 243.9K Work, Benefits & Business
  • 598.7K Mortgages, Homes & Bills
  • 176.9K Life & Family
  • 257.2K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.