1
This site rocks! I am trying to run a simple .bat file on Server 2012 that will ping another server, filter out all the lines except one, and then write to a file for later use (I then want that file sent somewhere, but that is a project for another discussion!).
I have pieced together some commands from searching this forum, and have the commands needed to make this happen. When I run these commands one at a time from ms-dos, it works. However, when it stick them all into a bat file something gets messed up. I don't have much experience with Server os's, so it could be something simple I am missing. Any help would be appreciated.
Here are my instructions
ping 10.18.89.154 >C:\pinglog.txt
FOR /F "skip=8 delims=" %i in (C:\pinglog.txt) do @echo %i >C:\TEMP.TXT
SET /P SHOW= < C:\TEMP.TXT
ECHO %SHOW% >C:\pinglog.txt
And here is the result when run manually:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
But when I run those commands in a batch file, the cmd window hangs on the first line, shows the below text in the cmd window and produces a blank file...
C:\Users\administrator.WSI\Documents>ping 10.18.89.154 1>C:\pinglog.txt
Any Thoughts?
Based on what you've written, I'm guessing you did not have the same problem as the original question. That dealt with syntax, and your question doesn't note a syntax-issue-resolving solution. Please read questions carefully and make sure you have something to actually add to the conversation before you post. – music2myear – 2017-06-12T23:07:36.060
This is part of the original question: "When I run these commands one at a time from ms-dos, it works. But when I run those commands in a batch file, the cmd window hangs on the first line, shows the below text in the cmd window and produces a blank file..." This is exactly the problem I faced and resolved as stated in my original post. The problem I just quoted was not addressed. – user2832948 – 2017-06-14T13:46:35.407
Adding that information to your answer post would make how it fits into this context more clear. – music2myear – 2017-06-14T15:51:59.517
Also, when OP uses the word "hang" they aren't using the correct term. When you run a PING command and output it to text, nothing it written to the terminal while the command is running, as you have redirected all output to the designated text file. This gives the appearance of a hang, but nothing is actually hanging. It is just working in the background. You'll get this behavior with any command that takes time to run whose output you redirect. There can be actual hangs (the program has encountered an error it cannot handle), but OP was not describing a hang, simply unexpected behavior. – music2myear – 2017-06-14T15:55:40.737