【问题标题】:Trying to redirect stdout to a file尝试将标准输出重定向到文件
【发布时间】:2013-09-11 04:47:05
【问题描述】:

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

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

【问题讨论】:

    标签: vbscript stdout


    【解决方案1】:

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

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

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

    C:\&gt;<b>cscript //NoLogo script.vbs &gt;C:\path\to\your.txt</b>

    时间戳可以这样打印:

    StdOut.WriteLine Now
    

    我不确定您所说的“位置”到底是什么意思。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      相关资源
      最近更新 更多