shell robocopy

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

tvonbrasch
Posts: 359
Joined: Fri Apr 15, 2011 5:35 am

shell robocopy

Postby tvonbrasch » Mon Aug 20, 2018 11:53 am

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 125 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 125 times


What am I doing wrong?
Thomas

EViews Steve
EViews Developer
Posts: 524
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: shell robocopy

Postby EViews Steve » Mon Aug 20, 2018 1:41 pm

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

tvonbrasch
Posts: 359
Joined: Fri Apr 15, 2011 5:35 am

Re: shell robocopy

Postby tvonbrasch » Mon Aug 20, 2018 9:58 pm

Perfect Steve, thanks for the quick reply!
Thomas


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 5 guests