views:

187

answers:

1

Hi,

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, http://stackoverflow.com/questions/445121/svn-dump-fails-with-wscript-shell/2400011#2400011 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
A: 

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 
ghostdog74
Thanks for the reply. If i ran "svnadmin dump" directly from the command line, I would see: * Dumped revision 100. * Dumped revision 101. * Dumped revision 102... etcHow do i capture these output information then? These info are obviously not sent to stdout since c:\fullbackup never contains the above info.
Dexton
you can remove the output redirection to `c:\fullbackup` and just use the `do while` loop you have got.
ghostdog74
Running "svnadmin dump C:\svn_repos C:\fullbackup" w/o output redirection from the command line, a host of dump data which is usually stored in the dump file will appear on screen.If I ran the command "svnadmin dump C:\svn_repos > C:\fullbackup" from the command line, a dump file would be created but appearing on screen would be verbose (i think) information (i.e. * Dumped revision 100. * Dumped revision 101. etc). How do i caputure this "verbose" information and yet have a dump file?
Dexton
you can create an output file yourself. see my edit.
ghostdog74
Thank you for the continued patience in helping me resolve the issue. I have made the recommended changes (pls see edited post above). The problem is that the operation hangs or stops after a while (i.e. it never completes). I did however discover that the dump information i was looking for is output through stderr. Any further advice?
Dexton
ghostdog74
yes, that would capture the dump information i was looking for but it doesnt create the dump file :( hang on.. THANKS! I got it! Solution as edited in the original post under "Solution". Thank you very much and for not giving up on me :DP.S: I still do not understand why i had to create a new command interpreter "%comspec% /c " to get svnadmin dump to work though. Is it because of the redirection symbol which needs a command interpreter to interprete?
Dexton
wrt batch, i am sorry i can't really help. hope someone familiar with comspec can help you. maybe your can specify the full path of your `svnadmin` command in your vbscript, remove the `comspec` and try again
ghostdog74
as mentioned it may be because of the redirection symbol which is a command which is built into the command interpreter therefore the need to invoke it via "comspec". This link http://technet.microsoft.com/en-us/library/ee692837.aspx explains it better: "Tools such as dir are not programs; they are more like parameters to the cmd.exe (or command.exe), so you need to specify %COMSPEC% to make them work."
Dexton