【问题标题】:How to save ms of ping in in txt file?如何在txt文件中保存毫秒的ping?
【发布时间】:2014-05-08 14:20:05
【问题描述】:

我想用例如:

ping google.com -t

Antwort von 193.99.144.80: Bytes=32 Zeit=17ms TTL=244

并且只想将 ms 保存在文本文件中。

我该怎么做?

【问题讨论】:

    标签: batch-file ping


    【解决方案1】:

    这使用了一个名为 repl.bat 的辅助批处理文件 - 从以下位置下载:https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

    repl.bat 放在与批处理文件相同的文件夹中或路径上的文件夹中。

    @echo off
    set ip=www.google.com
    ping %ip% -t |repl ".*?=.*?=([0-9]*).*TTL=.*" "$1" A >>textfile.txt
    

    【讨论】:

    • repl.bat 到底在做什么?
    • 它提取第二个等号之后的数字,在包含TTL=的行中
    【解决方案2】:
    for /f "tokens=7delims== " %%a in ('ping google.com^|find /i "Antwort"') do set ms=%%a
    echo %ms%
    set "ms=%ms:~0,-2%"
    echo %ms%
    

    选择你想要的格式...

    如果您想要最后一行的结果(平均是英文的第 6 项)然后使用 tokens=6 并删除 ^find /i "Antwort"

    【讨论】:

    • for 命令不会吐出任何内容,因为ping 命令永远不会结束。
    • @foxidrive :很公平。已修改,但无休止地简单地ping 似乎没有什么意义。没有更多细节......
    猜你喜欢
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多