问题
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