Page 1 of 1

shell robocopy

Posted: Mon Aug 20, 2018 11:53 am
by tvonbrasch
Hi

I am struggling with the shell command. When i type

Code: Select all

shell robocopy C:\tvb\ztobedeleted\test1 C:\tvb\ztobedeleted\test2
I get the error message
robocopy.PNG
robocopy.PNG (6.68 KiB) Viewed 4098 times
However, when i type the command directly in CMD, the folder is copied without a problem, see
robocopy2.PNG
robocopy2.PNG (29.71 KiB) Viewed 4098 times
What am I doing wrong?
Thomas

Re: shell robocopy

Posted: Mon Aug 20, 2018 1:41 pm
by EViews Steve
The SHELL command is similar to SPAWN, but it is hard-coded to look for a specific return value of 0 (if you provide arguments after the SHELL command).

It turns out that ROBOCOPY.exe returns 0 only if no files were copied. It returns 1 if at least one file was copied and so EViews assumed this was a problem (the garbage being displayed as the error message was it showing an uninitialized string). So you should use SPAWN instead so that it will ignore any exit codes.

Code: Select all

spawn robocopy C:\tvb\ztobedeleted\test1 C:\tvb\ztobedeleted\test2
If you wanted to make sure that robocopy actually copied at least one file, you could tell SPAWN to look for an exit code value of 1:

Code: Select all

spawn(exit=1) robocopy C:\tvb\ztobedeleted\test1 C:\tvb\ztobedeleted\test2
Steve

Re: shell robocopy

Posted: Mon Aug 20, 2018 9:58 pm
by tvonbrasch
Perfect Steve, thanks for the quick reply!
Thomas