xcopy redirection

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

xcopy redirection

#1 Post by drgt » 03 Dec 2011 05:34

On the command xcopy *.* d:\directory /e /c /h >c:\log.txt a warning that a file was not copied because it was corrupt comes to the screen instead of the log file. The warning does not state the name of the file.

How can we make the warning to go to the log file under the appropriate file name?

Thanks

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: xcopy redirection

#2 Post by Ed Dyreen » 03 Dec 2011 05:49

'

Code: Select all

2> "c:\log.txt" xcopy /e /c /h *.* "d:\directory"

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: xcopy redirection

#3 Post by orange_batch » 03 Dec 2011 07:42

Code: Select all

xcopy *.* d:\directory /e /c /h >c:\log.txt 2>&1

2>&1 is errors and output. http://ss64.com/nt/syntax-redirection.html
Last edited by orange_batch on 04 Dec 2011 05:08, edited 2 times in total.

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

xcopy redirection

#4 Post by drgt » 03 Dec 2011 10:48

Thanks guys!!!

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy redirection

#5 Post by alan_b » 03 Dec 2011 11:10

generally this is good, but not always

Code: Select all

2>&1 is errors and output. 


Reg.Exe has the special ability to simultaneously issue
Access Denied (or equivalent) via StdErr,
and
Data values via StdOut.

For all I know there are other commands with this special ability.

In this case my script was getting a report on each of a large quantity of keys with their subkeys and values.
Some sub-keys had permissions set to deny,
so simultaneously the name of the key was sent via StdOut whilst the unreadable contents message was sent via StdErr.

I found 99.9% similarity in the quantity of messages captured by running the script.
I suspected a race hazard conflict.
I changed the destination from a file in the same 12 MB C:\ partition as the script, to instead append to a file at the opposite end of the 160 MB HDD.
That immediately increased the conflict,
and message loss increased from 0.1% to 10%.

I disabled caching of writes to the HDD and that immediately prevented any data loss,
so the conflict was in the way that XP Home cached these messages on my Laptop.

Unfortunately this cure resulted in the Laptop taking 2 or 3 times as long to start-up and allowe me to log on.

My final solution was to process only one command at a time,
and redirect the two streams to two different files in non-append mode,
and then copy-append one file to the other,
and then copy-append this file to the ultimate destination

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

xcopy redirection

#6 Post by drgt » 03 Dec 2011 11:39

Oops, here is another issue:

If a filename is non english (in my case greek) then its name appears gibberish in the log.txt file

I tried cmd /u /c xcopy *.* D:\directory /e /c /h >>c:\log.txt 2>&1

and chcp 1237

without success :(

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

xcopy redirection

#7 Post by drgt » 03 Dec 2011 15:18

Anyone?

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: xcopy redirection

#8 Post by orange_batch » 03 Dec 2011 21:25

@alan_b - Not sure if it's the same problem, but is it a simultaneous file access error?? I have encountered that before and created a solution. My situation was multiple command prompt instances conflicting when writing to the same file, so I'm not sure about a single command's output though.

Code: Select all

for /f "delims=" %%a in ('command') do set "error=%%a"

:retry
(echo:!error!>>log.txt)2>nul||goto retry

Simply hinges on the success of trying to write to a file.

@drgt Those gibberish characters still may represent the codepage characters within command prompt. Though they are not human-readable, the computer can still read them.

For example, lambda and xi, Λ and Ξ, will appear in notepad as Ë and Î under codepage 1253, or ¶ and ½ under codepage 869.

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

Re: xcopy redirection

#9 Post by drgt » 03 Dec 2011 23:39

orange_batch wrote:@drgt Those gibberish characters still may represent the codepage characters within command prompt. Though they are not human-readable, the computer can still read them.

For example, lambda and xi, Λ and Ξ, will appear in notepad as Ë and Î under codepage 1253, or ¶ and ½ under codepage 869.


Granted. The thing is how to make them appear correctly in the log file so I can read them too!

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: xcopy redirection

#10 Post by orange_batch » 03 Dec 2011 23:51

cmd /u should work unless xcopy modifies the characters, but you said you tried that so you may be out of luck.

Paste into command line:

Code: Select all

cmd /u /c echo:ΛΞ>greek.txt
notepad greek.txt
pause
del greek.txt

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

xcopy redirection

#11 Post by drgt » 04 Dec 2011 00:31

orange_batch wrote:... but you said you tried that so you may be out of luck.


Yes, out of luck. cmd /u works on dir but not on xcopy for some reason.
Do you know of a 3rd party app that can convert the gibberish in readable?

By the way, chcp returns 737 on my pc.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy redirection

#12 Post by alan_b » 04 Dec 2011 02:43

First copy to the destination as before

Then copy with extra option switches /D /F, but DO NO Redirect to file - let the output appear on screen

/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.


With no date specified, it should ONLY attempt to copy the file that is corrupt.
Perhaps the /F StdOut will show more clearly what is obscure with the StdErr message.

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

xcopy redirection

#13 Post by drgt » 04 Dec 2011 04:16

Alan

The issue here is not to find the corrupted files that did not copy, Those are listed in the log file.

The issue now is how to properly display (in the log file) filenames that are NON english (greek in my case).

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: xcopy redirection

#14 Post by orange_batch » 04 Dec 2011 05:12

I do not know if it will make a difference, but I suggest trying sfk copy: http://sourceforge.net/projects/swissfileknife/ It works very similarly to xcopy with a plain /D switch/etc and uses Windows built-in CopyFileEx API function.

Or alternatively, robocopy: http://www.microsoft.com/download/en/de ... n&id=17657

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

xcopy redirection

#15 Post by drgt » 04 Dec 2011 05:32

Thanks orange_batch

I 'll try that.

I thought to replace the gibberish with the entries I get from the dir command (used with cmd /u), but then again I won't know If I am replacing the right gibberish with the correct name...

That's why I asked if there is a utility that turns gibberish into readable characters...

Thanks again

Post Reply