【问题标题】:VBScript record command line output to text (log) fileVBScript 将命令行输出记录到文本(日志)文件
【发布时间】:2014-02-10 20:41:14
【问题描述】:

我查看了所有重定向/导出命令行到文本文件的答案,但在这种情况下没有任何作用。我正在测试我们的软件,需要使用几个 XML 文件来运行应用程序。我已经编写了 VBScript 来针对应用程序运行文件夹中的所有 XML,但是我需要将命令窗口中的所有内容捕获到文本文件 (run.log) 中。

这是我拼凑出来的:

Option Explicit

Dim FSO, FLD, FIL, str, Expath, strFolder, objShell, objFSO, strFile, objFile

    set objShell = WScript.CreateObject ("WScript.Shell")
    Set FSO = CreateObject("Scripting.FileSystemObject")

'defines values 
    strFile = "Run.log"
    strFolder = "C:\SDK Testing PDFL 10\XML\"
    Expath = "C:\Program Files\ICEsdk600022\bin\FineEyeProcessExe.exe"
    objShell.CurrentDirectory = "C:\SDK Testing PDFL 10"

'defines the directory where the XML resides
    set FLD = FSO.GetFolder(strFolder)

'defines loop parameters
    For Each Fil In FLD.Files

'searches for XML files within loop
        If UCase(FSO.GetExtensionName(Fil.name)) = "XML" Then

'builds commandline
            str = chr(34) & Expath & chr(34) & chr(32) & chr(34) & strFolder & Fil.Name & chr(34)

'writes string to log           
        set objFSO = CreateObject("Scripting.FileSystemObject")
        set objFile = objFSO.OpenTextFile(strFolder & strFile, 8, True)
        objFile.WriteLine(str)
        objFile.Close

'runs command
            objShell.Run str

'shows string           
            MsgBox str

'writes output to log           
            'set objFSO = CreateObject("Scripting.FileSystemObject")
            'set objFile = objFSO.OpenTextFile(strFolder & strFile, 8, True)
            'objFile.WriteLine()
            'objFile.Close
        End If
    Next

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    你可以修改这一行..

    objShell.Run str
    

    ..到这样的东西..

    objShell.Run "cmd /c " & str & " > log.txt"
    

    这会将 C:\Program Files\ICEsdk600022\bin\FineEyeProcessExe.exe 的输出转储到 log.txt

    【讨论】:

    • 我一直在尝试使用它,实际上 %comspec% 没有成功。您向我指出的是寻找正确定义工作目录和扩展使用 & 允许我更深入地研究日志记录。
    猜你喜欢
    • 1970-01-01
    • 2019-04-24
    • 2017-05-28
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2010-09-18
    • 2013-03-12
    相关资源
    最近更新 更多