简体   繁体   English

vbscript调用svnadmin转储

[英]vbscript calling svnadmin dump

Running the following vbscript to call svnadmin dump fails (ie no dump is being created) 运行以下vbscript调用svnadmin转储失败(即未创建任何转储)

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

I discovered from another post, svn dump fails with WScript.Shell that i had to create a new command interpreter using cmd as follows: 我从另一篇文章中发现, svn dump无法使用WScript.Shell ,我必须使用cmd创建一个新的命令解释器,如下所示:

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

This successfully created the dump but I could never read the output information (ie * Dumped revision 100. * Dumped revision 101. etc). 这样成功创建了转储,但是我从不读取输出信息(即*转储修订版100。*转储修订版101。等等)。 I tried 我试过了

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

but nothing ever gets displayed. 但什么也没显示。

May I know how i can read the output information and also why I needed to create a new command interpreter using "%comspec% /c" before the svnadmin dump command would execute correctly? 我可以知道如何读取输出信息,为什么还要在svnadmin dump命令正确执行之前需要使用“%comspec%/ c”创建一个新的命令解释器? Thanks. 谢谢。

Regards, Dexton 问候,德克斯顿

Edited Code: 编辑代码:

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

Solution: 解:

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

you can't read the status because you are redirecting all your stdout to c:\\fullbackup . 您无法读取状态,因为您将所有标准输出重定向到c:\\fullbackup You should open the file c:\\fullbackup and read the contents instead. 您应该打开文件c:\\fullbackup并阅读其中的内容。

Update: you can write your status to an output file, something like this 更新:您可以将状态写入输出文件,类似这样

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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM