2010-03-09 58 views
0

運行下面的VBScript調用svnadmin的轉儲失敗(即正在創建沒有轉儲)VBScript中調用svnadmin的轉儲

Set objShell = CreateObject("WScript.Shell") 
Set objShellExec = objShell.Exec("svnadmin dump C:\svn_repos > C:\fullbackup") 

我從另一篇文章,svn dump fails with WScript.Shell,我不得不創建一個使用CMD作爲一個新的命令解釋器發現如下:

Set objShellExec = objShell.Exec("%comspec% /c" & "svnadmin dump C:\svn_repos > C:\fullbackup") 

這成功創建轉儲,但我永遠無法讀取輸出信息(即*轉儲的修訂100 *轉儲的修訂101等)。我試過

Do While objWshScriptExec.Status = 0 
    Wscript.Echo objShellExec.StdOut.Readline 
    Wscript.Echo objShellExec.StdErr.Readline 
    WScript.Sleep 100 
Loop 

但是什麼也沒有顯示。

我可以知道如何讀取輸出信息,以及爲什麼我需要在svnadmin dump命令正確執行之前使用「%comspec%/ c」創建新的命令解釋器?謝謝。

問候, Dexton推出

編輯代碼:

Set objShell = CreateObject("WScript.Shell") 

Set objFS = CreateObject("Scripting.FileSystemObject") 

strOutput = "c:\svn_backup\fullbackupa" 

Set objOutFile = objFS.CreateTextFile(strOutput,True) 

Set objShellExec = objShell.Exec("%comspec% /c " & "svnadmin dump C:\svn_repos") 

Do While objShellExec.Status = 0 
    stdoutline=objShellExec.StdOut.Readline 
    'Wscript.Echo stdoutline 'echo to standard output 
    Wscript.Echo objShellExec.StdErr.Readline 
    objOutFile.WriteLine(stdoutline & vbCrLf) 'write to file at the same time 
    WScript.Sleep 100 
Loop 


objOutFile.Close 

解決方案:

Set objShell = CreateObject("WScript.Shell") 

Set objFS = CreateObject("Scripting.FileSystemObject") 

strOutput = "c:\svn_backup\fullbackupa" 

Set objOutFile = objFS.CreateTextFile(strOutput,True) 


Set objShellExec = objShell.Exec("%comspec% /c " & "svnadmin dump C:\svn_repos > c:\svn_backup\fullbackupb") 

Do While objShellExec.Status = 0 
    stdoutline=objShellExec.StdErr.Readline 
    Wscript.Echo stdoutline 'echo to standard output 
    'Wscript.Echo objShellExec.StdErr.Readline 
    objOutFile.WriteLine(stdoutline & vbCrLf) 'write to file at the same time 
    WScript.Sleep 100 
Loop 


objOutFile.Close 

回答

0

,因爲要重定向所有標準輸出到c:\fullbackup您無法讀取狀態。您應該打開文件c:\fullbackup並改爲閱讀內容。

更新:你可以寫你的狀態輸出文件,像這樣

Set objFS = CreateObject("Scripting.FileSystemObject") 
strOutput = "c:\fullbackup" 
Set objOutFile = objFS.CreateTextFile(strOutput,True) 
... 
Do While objWshScriptExec.Status = 0 
    stdoutline=objShellExec.StdOut.Readline 
    Wscript.Echo stdoutline 'echo to standard output 
    'Wscript.Echo objShellExec.StdErr.Readline 
    objOutFile.WriteLine(stdoutline & vbCrLf) 'write to file at the same time 
    WScript.Sleep 100 
Loop 
.... 
objOutFile.Close 
+0

感謝您的答覆。如果我直接從命令行運行「svnadmin dump」,我會看到: * Dumped revision 100. * Dumped revision 101. * Dumped revision 102 ... etc 如何捕獲這些輸出信息呢?這些信息顯然不會發送到標準輸出,因爲c:\ fullbackup從不包含上述信息。 – Dexton 2010-03-09 08:54:12

+0

你可以刪除輸出重定向到'c:\ fullbackup',並使用'do while'循環。 – ghostdog74 2010-03-09 09:04:57

+0

從命令行運行「svnadmin dump C:\ svn_repos C:\ fullbackup」w/o輸出重定向時,通常存儲在轉儲文件中的大量轉儲數據將顯示在屏幕上。 如果我從命令行運行命令「svnadmin dump C:\ svn_repos> C:\ fullbackup」,將會創建一個轉儲文件,但在屏幕上出現將是冗長的(我認爲)信息(即* Dumped revision 100。 *傾銷版本101等)。 我如何caputure這個「詳細」的信息,但有一個轉儲文件? – Dexton 2010-03-10 02:56:59