Redirect output processed via vbscript (cscript) to file

拜拜、爱过 提交于 2019-12-22 08:44:04

问题


Issue with command output:

I am attempting to have a continuous ping report back to a text file.

Started with:

ping 127.0.0.1 -t >> C:Textping.txt

Works great

I also want to have timestamps listed before each ping

So Wrote:

Dim str
Do While Not WScript.StdIn.AtEndOfStream
  str = WScript.StdIn.ReadLine
  WScript.StdErr.WriteLine now & " - " & str
Loop

Saved it as timestampLog.vbs on my desktop and dropped a copy into my system 32 folder.

Put all of this into a batch file:

ping 127.0.0.1 -t | cscript //nologo timestamplog.vbs >> C:Pingtest1.txt

It works perfectly except that the output is printing to command prompt and Pingtest1.txt while created by the batch file is empty.

Can someone please assist me with getting the output to Pingtest1.txt?


回答1:


You are running it with cscript, and writing output to STDERR (using WScript.StdErr.WriteLine). So you could use:

ping 127.0.0.1 -t | cscript //nologo timestamplog.vbs 2> C:/Pingtest1.txt
                                                      ^^

> denotes STDOUT, 2> denotes STDERR.



来源:https://stackoverflow.com/questions/16572252/redirect-output-processed-via-vbscript-cscript-to-file

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