我在一个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文件中。
希望我的解释是正确的。
提前感谢!
发布于 2012-05-07 22:03:33
您可以使用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.Closehttps://stackoverflow.com/questions/10123577
复制相似问题