vbs 一段PING值到TXT文件

来源:百度知道 编辑:UC知道 时间:2024/05/05 22:43:06
Set shell = WScript.CreateObject("WScript.Shell")
Set re=New RegExp
re.Pattern = "^Reply|^Request"
Set myping=shell.Exec("ping 219.150.32.132 -t")
while Not myping.StdOut.AtEndOfStream
strLine = myping.StdOut.ReadLine()
r=re.Test(strLine)
If r Then
WScript.Echo date & " "& time & chr(9) & strLine
End if
Wend

保存到T.VBS

在用CMD调入T.VBS
cscript t.vbs

结果输出为

Microsoft (R) Windows Script Host Version 5.7
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。

2009-10-7 16:25:34 Reply from 219.150.32.132: bytes=32 time=49ms TTL=245
2009-10-7 16:25:35 Reply from 219.150.32.132: bytes=32 time=50ms TTL=245
2009-10-7 16:25:36 Reply from 219.150.32.132: bytes=32 time=47ms TTL=245
2009-10-7 16:25:37 Reply from 219.150.32.132: bytes=32 time=49ms TTL=245

我现在想吧PING值保存到TXT文件里 应该怎么编译?

将第四行代码改为:
Set myping=shell.Exec("cmd /c ping 219.150.32.132 -t>>info.txt")
运行一下就可以看到效果了

调用FileSystemObject对象,可以进行很多文件操作,下面是例子,具体请查资料

Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile("c:\testfile.txt", True)
f.WriteLine("写入一行文本")
F.Close

set os=createobject("wscript.shell")
os.run "cmd /c ping 219.150.32.132 >D:\ping.txt",0

不知道这个是不是你想要的。