简体   繁体   English

如何创建从批处理文件复制ping信息的文本文件?

[英]How can I create a text file that copies ping info from the batch file?

I want to be able to ping a website such as www.google.com and then have it make a new text file with the results of said ping. 我希望能够对一个网站(例如www.google.com)进行ping操作,然后使其生成一个包含上述ping结果的新文本文件。

Here is the code of the ping: 这是ping的代码:

echo --------------------
echo TESTING CONNECTIVITY
echo --------------------
ping 127.0.0.1 -n 5 -w 3000
echo.
ping www.google.com -n 5 -w 3000

I want that to be in a text file after it is done. 完成后,我希望将其保存在文本文件中。

Pipe it to a file and use type to display the results also in the console 将其通过管道传输到文件,并使用type在控制台中显示结果

ping www.google.com > result.txt
type results.txt

or 要么

ping www.google.com | result.txt

The latter one will open the result.txt to show the result. 后者将打开result.txt以显示结果。

Or put a type results.txt after the ping to show the results on the console. 或在ping之后type results.txt ,以在控制台上显示结果。

另一种方法是将批处理文件的输出传递到文本文件中:

mypingbatch.bat >>file.log

If you want to log availabily periodically, schedule the following task: 如果要定期记录日志,请计划以下任务:

SET IP=www.google.com
SET STATUS=UNAVAILABLE
FOR /F "tokens=1-9 delims==< " %%a IN ('PING -n 1 -w 2500 %IP%') DO IF "%%h"=="TTL" SET STATUS=%%g
ECHO %DATE% %TIME% %IP% %STATUS% >> ping.%IP%.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM