Trying to redirect stdout to a file

佐手、 提交于 2020-12-12 04:40:31

问题


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

回答1:


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".



来源:https://stackoverflow.com/questions/18728030/trying-to-redirect-stdout-to-a-file

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