Windows 10: Batch file: Who can solve this mystery? Solved

  1.    31 Mar 2016 #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 ComputerSystem Spec

  2.    31 Mar 2016 #2

    Run ping /?

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


  3. Posts : 3,210
    10.5 Home 1803 x64
       31 Mar 2016 #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 capture_03312016_193835.jpg  
      My ComputerSystem Spec

  4.    31 Mar 2016 #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 ComputerSystem Spec


  5. Posts : 3,210
    10.5 Home 1803 x64
       31 Mar 2016 #5

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

  6.    31 Mar 2016 #6

    That's the answer! Renaming the file makes it work in Windows 10! It worked fine in XP as ping.bat.
    jfniss said: View Post
    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 ComputerSystem Spec


  7. Posts : 3,210
    10.5 Home 1803 x64
       31 Mar 2016 #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 capture_03312016_200234.jpg  
      My ComputerSystem Spec

  •    31 Mar 2016 #8

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


  •  

    Related Threads
    Solved Start a program from a batch file in Software and Apps
    4 Apps of mine run a batch file that -tries- to call/start and EXE program. These Batch files need to work with OS XP thru Win 10. Win 10 has a pop-up window asking user if its okay to run/execute my EXE. No other Win version does this and thus I...
    Can't download batch file in General Support
    Can't download batch file "10services_default.bat" to solve windows 10 start menu problem.
    Solved Writhing Batch File in General Support
    Here is my batch file but it will not delete the file? Must be missing something :( del "C:\Users\Larry\AppData\Local\TractorParts\tractor\ConfigSetting" Trying to delete the ConfigSetting File
    System Info Batch File in Chillout Room
    Hi Everyone, I thought it may be interesting to get input from others regarding this batch file. I was hoping for suggestions about: Information to add to the report. Ways of making the current code more efficient. Etc... A while back i...
    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 15:00.
    Find Us