【问题标题】:VBscript log responses of ResGen.exeResGen.exe 的 VBscript 日志响应
【发布时间】:2012-04-12 12:28:14
【问题描述】:

我正在使用 VBScript 使用 ResGen.exe 生成资源文件,需要收集 ResGen 的错误消息并将其写入文件中,已控制文件写入的部分(在此处显示的脚本中不存在但我知道怎么做)

'' Folder that contains the files 
folderpath = "C:\Users\Administrator\Desktop\Author\author\"
'Destination folder from generated files
destfolder = "C:\Users\Administrator\Desktop\Author\author\"
'Folder contains the text file with list of files names
listfolder = "C:\Users\Administrator\Desktop\Author\"
listfile = listfolder + "list.txt"
logfile = listfolder + "log.txt"

resgen = "ResGen.exe /compile"

Set objShell = CreateObject("WScript.Shell")

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.echo listfile
Set objFile = objFSO.OpenTextFile(listfile, ForReading)
Wscript.echo "Reading file"
Do While objFile.AtEndOfStream = False
    strLine = objFile.ReadLine
    cmdexec = Chr(34) + folderpath + strLine + "resx" + Chr(34) + " " + Chr(34) + destfolder + strLine + "resources" + Chr(34)
    execommand = resgen + " " + cmdexec 
    objShell.Run execommand,1,TRUE   
Loop
objFSO.Close

在 objShell.Run 行之后,我需要放什么来保存这个命令的响应?我尝试在命令后添加“>>”C:\log.txt“”,但不会生成资源文件,仅将响应保存在 txt 文件中。

希望我的解释正确。

提前致谢!

【问题讨论】:

    标签: vbscript logfile resgen


    【解决方案1】:

    您可以使用“Exec”方法获取WshScriptExec对象,并使用它的StdOut来获取命令的响应,如下图:

    '' Folder that contains the files 
    folderpath = "C:\Users\Administrator\Desktop\Author\author\"
    'Destination folder from generated files
    destfolder = "C:\Users\Administrator\Desktop\Author\author\"
    'Folder contains the text file with list of files names
    listfolder = "C:\Users\Administrator\Desktop\Author\"
    listfile = listfolder + "list.txt"
    logfile = listfolder + "log.txt"
    
    resgen = "ResGen.exe /compile"
    
    Set objShell = CreateObject("WScript.Shell")
    
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Wscript.echo listfile
    Set objFile = objFSO.OpenTextFile(listfile, ForReading)
    Wscript.echo "Reading file"
    Do While objFile.AtEndOfStream = False
        strLine = objFile.ReadLine
        cmdexec = Chr(34) + folderpath + strLine + "resx" + Chr(34) + " " + Chr(34) + destfolder + strLine + "resources" + Chr(34)
        execommand = resgen + " " + cmdexec 
        '***************************************
        Set oExec = objShell.Exec(execommand)
        Do While oExec.Status = 0
            WScript.Sleep 1000
        Loop
        WScript.Echo oExec.StdOut.ReadLine
        '***************************************
    Loop
    objFSO.Close
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      相关资源
      最近更新 更多