简体   繁体   中英

vbscript calling svnadmin dump

Running the following vbscript to call svnadmin dump fails (ie 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 (ie * 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

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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