尝试将标准输出重定向到文件 [英] Trying to redirect stdout to a file

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

问题描述

我想将标准输出发送到带有日期戳和每台打印机位置的日志文件.

On Error resume NextDim objNetwork、StdIn、StdOut'初始化打印机连接对象Set objNetwork = CreateObject("WScript.Network")设置标准输入 = WScript.StdIn设置 StdOut = WScript.StdOut'连接每台打印机objNetwork.AddWindowsPrinterConnection "\\server\pr01"objNetwork.AddWindowsPrinterConnection "\\server\pr02"objNetwork.AddWindowsPrinterConnection "\\server\pr03"'删除旧打印机'objNetwork.RemoveWindowsPrinterConnection "\\old_server\printer_1"'objNetwork.RemoveWindowsPrinterConnection "\\old_server\printer_2

解决方案

如果您想从脚本中执行此操作,请打开文件而不是使用 WScript.StdOut:

Set fso = CreateObject("Scripting.FileSystemObject")...Set StdOut = fso.OpenTextFile("C:\path\to\your.txt", 2, True)...标准输出.关闭

否则将脚本创建的输出重定向到一个文件:

C:\>cscript//NoLogo script.vbs >C:\path\to\your.txt<小时>

时间戳可以这样打印:

StdOut.WriteLine 现在

我不确定您所说的位置"究竟是什么意思.

I'd like to send the stdout to a logfile with a datestamp and location for each printer.

On Error resume Next 

Dim objNetwork, StdIn, StdOut

'Initialize the printer connections object
Set objNetwork = CreateObject("WScript.Network")  
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut

'Connect each printer
objNetwork.AddWindowsPrinterConnection "\\server\pr01"
objNetwork.AddWindowsPrinterConnection "\\server\pr02"
objNetwork.AddWindowsPrinterConnection "\\server\pr03"

'Remove old printers
'objNetwork.RemoveWindowsPrinterConnection "\\old_server\printer_1"
'objNetwork.RemoveWindowsPrinterConnection "\\old_server\printer_2

解决方案

If you want to do it from within the script open a file instead of using WScript.StdOut:

Set fso = CreateObject("Scripting.FileSystemObject")
...
Set StdOut = fso.OpenTextFile("C:\path\to\your.txt", 2, True)

...

StdOut.Close

Otherwise redirect the output created by the script to a file:

C:\>cscript //NoLogo script.vbs >C:\path\to\your.txt


Timestamps can be printed like this:

StdOut.WriteLine Now

I'm not sure what exactly you mean by "location".

这篇关于尝试将标准输出重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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