VBscript log responses of ResGen.exe

245 Views Asked by At

I'm working on a VBScript to generate resource files with ResGen.exe and need to collect the error message of ResGen and write this in a file, have controlled the part of file write (is not present in the script show here but i know how to do it)

'' 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

After objShell.Run line, what I need to put to save the response of this command? I've tried adding " >> "C:\log.txt" " after the command but with this the resource files are not generated, only save the response in txt file.

Hope I have explained correctly.

Thanks in advance!

1

There are 1 best solutions below

0
On

You can use the "Exec" method to get the WshScriptExec object, and use it's StdOut to get the response of the command, as showed below:

'' 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