0
ping google.com >> ping.txt

that dosent work if i put it in a batch file and run the file

this is the output of ping.txt:

C:\Users\User\Desktop>ping google.com  1>>ping.txt  
C:\Users\User\Desktop>ping google.com  1>>ping.txt  
. 
. 
.
3
  • Is that all of the code in your batch? Just the one ping command? I am wondering if something else is causing issues. I know if I make a batch with just that ping command in it, it works.
    – iesou
    Commented May 8, 2012 at 13:06
  • i was working on other batch files at the same time, maybe that caused the problem? Commented May 8, 2012 at 13:25
  • it could have. One thing to make sure you include in all your batch files is a setlocal at the top and an endlocal at the bottom. That will get rid of any variables that you set in your batch so they don't bleed into any other processes should they have the same name. I'm not sure that's your problem here, but it can't hurt.
    – iesou
    Commented May 8, 2012 at 13:44

1 Answer 1

1

You're doing something strange with pipes.

This (from command line) will append the ping result to ping.txt file.

ping www.google.com >> ping.txt

Now create a batch file (testping.bat, for example) and put the same line inside it. If you run the batch file with following command you'll get the same result.

testping

If you redirect the output of the batch itself then what you'll get is the echo of the batch file commands! This is why this will not work as expected:

testping >> ping.txt
2
  • i created a batch file testping.bat and did what you said but its executing commands from ping.bat! if i rename ping.bat to anything problem solved. and i restarted the computer and still the same Commented May 8, 2012 at 13:14
  • you named your batch file as another program (ping.exe)? Remember that the execution order is determined by the PATHEXT environment variable. Commented May 8, 2012 at 13:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.