vbscript调用svnadmin dump

时间:2010-03-09 03:53:02

标签: svn vbscript dump svnadmin

运行以下vbscript来调用svnadmin dump失败(即没有创建转储)

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")

这成功创建了转储,但我永远无法读取输出信息(即* Dumped revision 100. * Dumped revision 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

1 个答案:

答案 0 :(得分: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