gpt4 book ai didi

scripting - 将 "ping"输出发送到变量

转载 作者:行者123 更新时间:2023-12-03 21:52:04 24 4
gpt4 key购买 nike

我正在尝试 ping 路由器中的一些 IP 地址。我使用此代码:

for {set n 0} {$n < 10} {incr n} {puts [exec "ping 199.99.$n.1]}

但这将显示输出。问题是我不想看到输出。我想将该输出发送到另一个变量中,并使用“regexp”搜索变量的内容并获得结果,然后完成剩下的事情。但我不知道该怎么做。

最佳答案

使用 set 命令。 puts 命令打印它的参数。

set pingOutput [exec ping "199.99.$n.1"]

如果您希望将所有 IP 的结果放在一个变量中,则

append

set allPingOutput ""
for {set n 0} {$n < 10} {incr n} {
append allPingOutput [exec ping "199.99.$n.1"]
}

关于scripting - 将 "ping"输出发送到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15846976/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com