[英]VBscript log responses of ResGen.exe
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) 我正在使用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
After objShell.Run line, what I need to put to save the response of this command? 在objShell.Run行之后,需要保存什么来保存此命令的响应? 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.
我试过在命令后添加“ >>“ C:\\ log.txt”“,但是不会生成资源文件,仅将响应保存在txt文件中。
Hope I have explained correctly. 希望我已经正确解释了。
Thanks in advance! 提前致谢!
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: 您可以使用“ 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.