here is some vbscript code you can play with (save it as "ping.vbs", then run
"cscript ping.vbs" in MS-DOS, to use somewhere else, comment out lines with "wscript.echo" ):Option Explicit
Dim rString
rString = "127.0.0.1" Dim Cmd
Dim fso
Dim cList Cmd = "%comspec% /c ping "& rString &" -a -n 1 -w 400 > c:\temp\pingresult.txt"
CreateObject("Wscript.Shell").Run Cmd, 0, True
Set fso = CreateObject("Scripting.FileSystemObject")
Set cList = fso.OpenTextFile ("c:\temp\pingresult.txt")
rString = cList.ReadAll
WScript.Echo rString
if instr(rString,"TTL") > 0 then
'successful
WScript.Echo "successful"
else
' failed
WScript.Echo "Failed"
end if
cList.close
set cList = nothing fso.GetFile("c:\temp\pingresult.txt").delete
set fso = nothing
"cscript ping.vbs" in MS-DOS, to use somewhere else, comment out lines with "wscript.echo" ):Option Explicit
Dim rString
rString = "127.0.0.1" Dim Cmd
Dim fso
Dim cList Cmd = "%comspec% /c ping "& rString &" -a -n 1 -w 400 > c:\temp\pingresult.txt"
CreateObject("Wscript.Shell").Run Cmd, 0, True
Set fso = CreateObject("Scripting.FileSystemObject")
Set cList = fso.OpenTextFile ("c:\temp\pingresult.txt")
rString = cList.ReadAll
WScript.Echo rString
if instr(rString,"TTL") > 0 then
'successful
WScript.Echo "successful"
else
' failed
WScript.Echo "Failed"
end if
cList.close
set cList = nothing fso.GetFile("c:\temp\pingresult.txt").delete
set fso = nothing
%comspec% /c 是什么意思?
2.%comspec% /c == command.com /c
Executes the specified command and returns
时没有判断是否到了文件尾。加入判断后问题解决。谢谢!