How to write a ping to a text file using VBS

帅比萌擦擦* 提交于 2019-12-02 08:55:49

The instruction Output.WriteLine (objCmdTest.run ("ping failboat")) will write the return value of the Run method to the output file. If you want to append the command output to an output file you have to either redirect the output in the command:

objCmdTest.run "%COMSPEC% /c ping failboat >>C:\vbs\test.txt", 0, True

or use Exec instead of Run:

Set ping = objCmdTest.Exec("ping failboat")
Do While ping.Status = 0
  WScript.Sleep 100
Loop
Output.WriteLine ping.StdOut.ReadAll

WScript.Shell's run method returns the process's exit code. In order to get access to an application's output, you need to use the exec method instead, and use the object that returns to get access to the process's standard output through its StdOut property.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!