将通过vbscript(cscript)处理的输出重定向到文件 [英] Redirect output processed via vbscript (cscript) to file

查看:179
本文介绍了将通过vbscript(cscript)处理的输出重定向到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题与命令输出:

我正在尝试将连续的ping报告返回到文本文件.

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

开始于:

ping 127.0.0.1 -t >> C:Textping.txt

效果很好

我也想在每次ping前列出时间戳记

I also want to have timestamps listed before each ping

所以写:

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

将其另存为我的桌面上的timestampLog.vbs,并将副本放入系统32文件夹中.

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

除了将输出打印到命令提示符并且批处理文件创建的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.

有人可以协助我将输出内容发送到Pingtest1.txt吗?

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

推荐答案

您正在使用cscript运行它,并将输出写入 STDERR (使用WScript.StdErr.WriteLine).因此,您可以使用:

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
                                                      ^^

>表示 STDOUT 2>表示 STDERR .

这篇关于将通过vbscript(cscript)处理的输出重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆