Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Robocopy does not run with variable???

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,25570
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Robocopy does not run with variable???
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Robocopy does not run with variable??? - 9/6/2005 12:21:36 AM   
  DaveThomson

 

Posts: 9
Score: 0
Joined: 8/21/2005
Status: offline
I have a script which runs Robocopy; however it does not run when using the variable strLogFile.  I have changed the input value of strCmd to 3 to maximize the window and it does not run.  If I hard code the file name of the log it works.  Code follows:


strCmd = "robocopy.exe \\172.16.112.211\inetpub$\"& strWebFolder &"\\172.16.112.130\inetpub$\"& strWebFolder & "/s /e /tee /r:2 /w:2 /log+: "& strLogFile
objCmd.Run strCmd, 0, true

Any help is appreciated.  I need this working by Today.

Thanks in advance
 
 
Post #: 1
 
 RE: Robocopy does not run with variable??? - 9/6/2005 12:27:59 AM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
Shouldnt there be an additional space after \inetpub$\"& strWebFolder & "/s
so instead it should look like \inetpub$\"& strWebFolder & " /s (extra space after " and before /s)
 
An easy way to find your problems is always to echo the string you made so insert a "wscript.echo StrCmd" and see what ur outputing.



_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to DaveThomson)
 
 
Post #: 2
 
 RE: Robocopy does not run with variable??? - 9/6/2005 12:35:57 AM   
  DaveThomson

 

Posts: 9
Score: 0
Joined: 8/21/2005
Status: offline
That is the weird thing.  I did set a message box before and after the command.  It looked correct and if you copy that command line, then use hard coded values it works.

My manager even looked at the script and was perplexed.  He is from the UNIX world and came up with an equivalent Perl script.  But I like to get this going.  I will look at the command again and insure there are spaces between the switches.

Thanks for pointing that out.

(in reply to DaveThomson)
 
 
Post #: 3
 
 RE: Robocopy does not run with variable??? - 9/6/2005 12:40:32 AM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
Looks like there should be another space after first strwebfolder and before \\172
StrWebFolder &" \\172.
 
Its easy to miss those small thing, ive done it more than once myself, really annoying when you finally find them ;)

/CM

_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to DaveThomson)
 
 
Post #: 4
 
 RE: Robocopy does not run with variable??? - 9/6/2005 1:35:00 AM   
  DaveThomson

 

Posts: 9
Score: 0
Joined: 8/21/2005
Status: offline
O.K.  I took those suggestions and sytactically the line looks good.  But it does not run!!!

Here is the revised executable line:





MsgBox strCmd

strCmd = "robocopy.exe \\172.16.12.211\inetpub$\"&strWebFolder & "  \\172.16.12.310\inetpub$\"&strWebFolder & "  /s /e /tee /r:2 /w:2 /log+:" & strLogFile
objCmd.Run strCmd, 0, true
MsgBox strCmd
MsgBox strLogFile 

I cut that line and put it in the command window, but of course had to remove the &, " and the variables.  Then it was able to run???  Now I noticed the line wrapped on the command line but it still ran so I don't know why it is not running in my script!  I commented On Error Resume Next and it does not generate any VB errors.

Any suggestions would be helpful.



(in reply to DaveThomson)
 
 
Post #: 5
 
 RE: Robocopy does not run with variable??? - 9/6/2005 1:40:40 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Use WScript.Echo to print the value of strCmd to the command window then copy and paste it here.

(in reply to DaveThomson)
 
 
Post #: 6
 
 RE: Robocopy does not run with variable??? - 9/6/2005 1:47:11 AM   
  DaveThomson

 

Posts: 9
Score: 0
Joined: 8/21/2005
Status: offline


That is the msgbox, is this what you are refering to?

The command in my code: MsgBox strCmd

(in reply to DaveThomson)
 
 
Post #: 7
 
 RE: Robocopy does not run with variable??? - 9/6/2005 2:04:14 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
I can't see that image. That is why I suggested using WScript.Echo so that you could paste the text here.

(in reply to DaveThomson)
 
 
Post #: 8
 
 RE: Robocopy does not run with variable??? - 9/6/2005 2:23:12 AM   
  DaveThomson

 

Posts: 9
Score: 0
Joined: 8/21/2005
Status: offline
O.K.  I did the following

cmd /k robocopy.exe \\172.16.12.21\inetpub$\"&strWebFolder & "  \\172.16.12.30\inetpub$\"&strWebFolder & "  /s /e /tee /r:2 /w:2 /log+:" & strLogFile

and got this error:

2005/09/06 11:19:21 ERROR 32 (0x00000020) Opening Log File C:\SYSTOOLS\LOGS\tes
.log
The process cannot access the file because it is being used by another process.

-------------------------------------------------------------------------------
  ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------
Started : Tue Sep 06 11:19:21 2005
  Source - \\172.16.12.211\inetpub$\test\
    Dest - \\172.16.12.130\inetpub$\test\
   Files :
Options : /TEE /S /E /COPY:DAT /R:2 /W:2
------------------------------------------------------------------------------
ERROR : Invalid Parameter #8 : "/log+:C:\SYSTOOLS\LOGS\test.log"
      Simple Usage :: ROBOCOPY source destination /MIR
            source :: Source Directory (drive:\path or \\server\share\path).
       destination :: Destination Dir  (drive:\path or \\server\share\path).
              /MIR :: Mirror a complete directory tree.
   For more usage information run ROBOCOPY /? or read Robocopy.Doc.
NOTE: Read "True Replication" in Robocopy.Doc prior to first use of /MIR !
****  /MIR can DELETE files as well as copy them !
C:\systools>

========

I think that is the issue?  I did the following to setup the file:

strWebFolder = wscript.arguments.item(0)
strLogFile = "C:\SYSTOOLS\LOGS\" & strWebFolder & ".log"
Set objStrLine = objFileSysObj.CreateTextFile(strLogFile, True)

Why is VBScript 'holding' onto the file if that is the case?, should I close the file before Robocopy uses it?  That is my initial thought.

(in reply to DaveThomson)
 
 
Post #: 9
 
 RE: Robocopy does not run with variable??? - 9/6/2005 2:41:52 AM   
  DaveThomson

 

Posts: 9
Score: 0
Joined: 8/21/2005
Status: offline
I am getting closer and still welcome to suggestions, sometimes you just want the damm thing to work that you sometimes get sloppy.  Anyway here is what I got to get it to work.

strWebFolder = wscript.arguments.item(0)
strLogFile = "C:\SYSTOOLS\LOGS\" & strWebFolder & ".log"
Set objStrLine = objFileSysObj.CreateTextFile(strLogFile, True)
strRoboLog = strLogFile
objStrLine.close
'

I created a file, then set the value of the robo log to that new file.  Then I closed the original file.  To me that is not elegant and sloppy?  Is there a better way?  My requirements is to create the log with the name of the folder.  We have over 10 copy jobs and is better to organize them by folders.

Again any suggestions is helpful.


(in reply to DaveThomson)
 
 
Post #: 10
 
 RE: Robocopy does not run with variable??? - 9/6/2005 2:52:35 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Well, if you only need robocopy to log to the file, then using a redirect ('>') in the command line will cause the file to be created. If however you plan to log to the file from the vbscript before you let robocopy write to it, then you do need to close it before the command line call. You could also look at the Logger class that I posted in the Post A Script section. It always closes the file after a write, so you should never have a file left stranded open.

(in reply to DaveThomson)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Robocopy does not run with variable??? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts