vbscript 调用 svnadmin dump

发布于 2024-08-24 04:49:15 字数 2173 浏览 17 评论 0原文

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

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

我从另一篇文章中发现 svn dump因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

Running the following vbscript to call svnadmin dump fails (i.e. no dump is being created)

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:

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 (i.e. * Dumped revision 100. * Dumped revision 101. etc). 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? 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酸甜透明夹心 2024-08-31 04:49:15

您无法读取状态,因为您将所有标准输出重定向到 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 

you can't read the status because you are redirecting all your stdout to c:\fullbackup. You should open the file c:\fullbackup and read the contents instead.

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 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文