Batch file: Who can solve this mystery?


  1. Posts : 41
    Windows 10
       #1

    Batch file: Who can solve this mystery?


    I recenty migrated to Windows 10 from XP. Years ago, I made a batch file, ping.bat, to test my Internet connection and DNS server:

    ping 98.139.183.24
    ping yahoo.com
    ping nytimes.com
    pause

    It works fine in XP, but when I run it in Windows 10, it goes into an endless loop after reading the first line, without returning a result or going on to the next line. But if I open it in Notepad and copy and paste the text into a Window 10 Command Prompt window, it works fine--just like in XP. What's going on? A couple of other batch files I made for XP seem to work the same in Windows 10.
      My Computer


  2. Posts : 18,424
    Windows 11 Pro
       #2

    Run ping /?

    that will give you the options of how long to ping for.
      My Computer


  3. Posts : 5,443
    Windows 11 Home
       #3

    The bat file works just fine on mine PC, maybe a problem with your DNS server.
    Anyway, that webpage probably reports to your DNS, that it is down right now.
    Attached Thumbnails Attached Thumbnails Batch file: Who can solve this mystery?-capture_03312016_193835.jpg  
      My Computer


  4. Posts : 41
    Windows 10
    Thread Starter
       #4

    My question is: Why do I get one result (endless loop) if I run the .bat file in Windows 10, but a different result (works fine) if I paste the exact text of the batch file into a Windows 10 Command Prompt window?
      My Computer


  5. Posts : 5,443
    Windows 11 Home
       #5

    I see, that is funny, rename your file to something else, not ping.
      My Computer


  6. Posts : 41
    Windows 10
    Thread Starter
       #6

    That's the answer! Renaming the file makes it work in Windows 10! It worked fine in XP as ping.bat.
    jfniss said:
    My question is: Why do I get one result (endless loop) if I run the .bat file in Windows 10, but a different result (works fine) if I paste the exact text of the batch file into a Windows 10 Command Prompt window?
      My Computer


  7. Posts : 5,443
    Windows 11 Home
       #7

    then the interpreter (cmd.exe) searches/probes the paths in the environment variable %PATH% for something that looks like ping ... and it does that by appending each suffix from %PATHEXT% which contains something like .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC. so, calling just ping from the ping.batleads to a search for ping.comping.exeping.bat and so on. The interpreter will find a ping.bat in the current working directory (your ping.bat) and calls it.
    So, you will have a nice recursion here: ping.cmd executes the first line, searches for "ping", finds "ping.cmd", executes the first line, searches for "ping", finds "ping.cmd", executes the first line, searches for "ping", finds "ping.cmd" ...
    Source: windows 7 - Why does the PING command in my batch file execute in a loop? - Super User

    I might actually use it as a prank, especially since April 1st is coming. :)
    Attached Thumbnails Attached Thumbnails Batch file: Who can solve this mystery?-capture_03312016_200234.jpg  
      My Computer


  8. Posts : 18,424
    Windows 11 Pro
       #8

    TairikuOkami said:
    I see, that is funny, rename your file to something else, not ping.
    Brilliant!
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:15.
Find Us




Windows 10 Forums