0

我正在使用 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 文件中。

希望我已经正确解释。

提前致谢!

4

1 回答 1

0

您可以使用“ 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
于 2012-05-07T14:03:32.997 回答