2012-04-12 12 views
0

ResGen.exeでリソースファイルを生成するためにVBScriptで作業していて、ResGenのエラーメッセージを収集してこれをファイルに書き込む必要があります。 objShell.Runライン後)ここでスクリプトのショーに存在するが、私はそれを行う方法を知っていないResGen.exeのVBscriptログ応答

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

、私は、このコマンドの応答を保存するために置くために必要なもの?コマンドの後に ">>" C:\ log.txt ""を追加しようとしましたが、このリソースファイルは生成されず、txtファイルにのみ応答が保存されます。

私は正しく説明しました。

ありがとうございます!

答えて

0

あなたはWshScriptExecオブジェクトを取得するには、「Execの」メソッドを使用することができ、及び下記に示すように、それはコマンドの応答を取得するには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