VBScript记录命令行输出到文本(日志)文件

时间:2014-02-10 20:41:14

标签: vbscript

我查看了所有重定向/导出命令行到文本文件的答案,但在这种情况下都没有。我正在测试我们的软件,需要使用多个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

1 个答案:

答案 0 :(得分:1)

您可以修改此行..

objShell.Run str

..对于这样的事情..

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

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