Page 1 of 1 1
Topic Options
#189396 - 2008-09-03 05:10 PM Anyone Know how to capture XCOPY errorlevel from a SHELL ?
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
I frequently use XCOPY or ROBOCOPY to move batches of files and folders complete with Attributes /K and ACL's /O
If I get an error code within the shell,eg a file could not copy of not found, KIX still reports OK when the shell terminates.

Does anyone know a means of passing the cmd errorlevel codes back to the script ?
 Code:
      $CMD='XCOPY "'+$fm+'" "'+$to+'" /c/e/q/g/h/r/k/o/v/y'
      shell $CMD
      IF @error = 0
       RD $fm /s
       IF @error <>0 and exist($fm)
         $=DebugIt("Failed to RD:"+$fm+"="+@SERROR)
       Endif
       ; Other Stuff
      Else
       ;Take Action
      Endif


Edited by MACE (2008-09-03 05:15 PM)

Top
#189403 - 2008-09-03 09:59 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: MACE]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, your code does not handle the error in any way:
 Code:
Else
       ;Take Action
endif


how about placing some code there?
like:
 Code:
@error " occured." ? get $ 


if it still reports no error, tell us your OS and kixtart type and version.
_________________________
!

download KiXnet

Top
#189417 - 2008-09-04 01:04 AM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: Lonkero]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
or, just redirect the output and results of the script, instead of halting it with waiting on input.
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#189442 - 2008-09-04 08:49 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: Björn]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that doesn't cut it if he has something else in the script.
as I assumed when he told kixtart exits without reporting an error.
_________________________
!

download KiXnet

Top
#189490 - 2008-09-05 10:24 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: Lonkero]
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
What I am trying to say is quite simple.
It does not appear to matter what the CMD Shell errorlevel is with XCOPY or ROBOCOPY, Successful or not, when the shell exits at the end of the command KIX is still saying @error = 0 so no kix error handling would ever get invoked.
If I cant pass codes back to KIX then I am going to have to generate temporary CMD scripts on the fly from/by KIX which handle all issues within the shell then exit to KIX which would then delete the temp CMD script before it loops etc.

wkix32 4.53.0.0 on XPP sp3

Top
#189491 - 2008-09-05 10:42 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: MACE]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
At least in this test it works as I would expect.

 Code:
break on

shell 'xcopy c:\winders\*.* c:\temp'
? "Kixtart reports:  " + @serror


Returns:
Kixtart reports: The system cannot open the file.

Top
#189493 - 2008-09-05 11:11 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: MACE]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Put the command into a batch file:
 Code:
$CMD='XCOPY "'+$fm+'" "'+$to+'" /c/e/q/g/h/r/k/o/v/y'
$File = '%TEMP%\myxcpy.bat'
Del $File
RedirectOutput($File)
'@Echo Off' ?
$Cmd ?
'Exit %ERRORLEVEL%' ?
RedirectOutput('')
Shell $File
'Returned ' @ERROR

See if that gives you anything better to see what's happening.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#189495 - 2008-09-05 11:45 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: MACE]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Personally I'd quit using XCOPY and stick with ROBOCOPY Version XP010
You can log everything and it is miles ahead of XCOPY for everything.
Log all then review the logs with Robocopy.

Top
#189496 - 2008-09-06 01:34 AM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: NTDOC]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Using RoboCopy it will also return a proper errorcode on exit.

I used this when we had to do a mass migration of HomeDrives from one server to another.

We found that error code 9 and 16 were the ones that we had to worry about the most. 0,1,2,3 were a success in one fashion or another.

here is how I used it.

 Code:
$Options = "/R:2 /Z /W:2 /CopyAll /MOV /E /V /NP /LOG+:\\serverx\c$\scripthome\logs\"+$AD_User+".txt"
Shell "%comspec% /c Robocopy " + $Directory + " " + "\\serverb\homedir$\" + Left($AD_User,1) + "\" +$AD_User+"\ "+ $Options
$results = @ERROR


Edited by Gargoyle (2008-09-06 01:40 AM)
Edit Reason: added code
_________________________
Today is the tomorrow you worried about yesterday.

Top
#189497 - 2008-09-06 01:53 AM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: Gargoyle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
I actually don't use either - XXCopy or Unison for large replications, especially over WAN or enterprise networks.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#189498 - 2008-09-06 02:22 AM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I've tried the Unison but out of the box it's a PITA to setup compared to Robocopy.

Don't get me wrong - Unison looks to be a great tool, but is not as easy to use or read about as Robocopy. Not sure why the author doesn't place it on a more commercial site (even like SourceForge or simlar) and document it a bit better, then it might get more recognition and use.

But basically within 30 seconds of reading you can use Robocopy, which I was not able to do the same thing with Unison.

Top
#189499 - 2008-09-06 03:54 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: NTDOC]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
It maybe a little late to join the party..

But, this is pretty cool and may have been already talked about. \:D Robocopy is very powerful and has extensive documentation.

The Robocopy GUI from Microsoft takes you step-by-step through the process.

http://technet.microsoft.com/en-us/magazine/cc160891.aspx

I also understand that you guys are trying to make Robo/X copy to work via KiX.

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#189504 - 2008-09-06 06:17 PM Re: Anyone Know how to capture XCOPY errorlevel from a SHELL ? [Re: Kdyer]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Mace, we have all tested kixtart error returning and have all got the error codes back, so there is something with your script or computer setup that is not right.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 820 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.068 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org