将 Ping 输出保存到文本文件

Save Ping Output to Text File

我正在使用这个批处理命令将 ping 输出保存到文本文件,

ping 10.226.2.10 -n 10 >>ping_ip.txt

但是当我将上述命令保存在批处理文件中并尝试 运行 它时,在命令提示符下 window 我的命令被转换为以下命令...

ping 10.226.2.10 -n 10  1>>ping_ip.txt

可以看到第二条命令1>>里多了1,不知道怎么来的..请大家提提意见

这只是正常行为。

在批处理文件中你有一些 input/output 流:

  • 0 = 标准输入流
  • 1 = 标准输出流
  • 2 = 标准错误流
  • 3-9 = 用户定义的流

您的 >> 运算符隐式重定向标准输出流,即它正在重定向流编号 1,并且 cmd 解析器转换命令

command >> output

进入

command 1>> output

显示基于隐式请求执行的显式命令

带有时间戳并附加到文件的 Powershell。

ping.exe -t example.com | Foreach{"{0} - {1}" -f (Get-Date),$_} | out-file .\ping.txt -append