我正在使用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文件中。
希望我已经正确解释了。
提前致谢!
答案 0 :(得分: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