xcopy redirection
Moderator: DosItHelp
xcopy redirection
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
How can we make the warning to go to the log file under the appropriate file name?
Thanks
Re: xcopy redirection
'
Code: Select all
2> "c:\log.txt" xcopy /e /c /h *.* "d:\directory"
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: xcopy redirection
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.
Re: xcopy redirection
generally this is good, but not always
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
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
xcopy redirection
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
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

-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: xcopy redirection
@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.
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.
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.
Re: xcopy redirection
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!
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: xcopy redirection
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:
Paste into command line:
Code: Select all
cmd /u /c echo:ΛΞ>greek.txt
notepad greek.txt
pause
del greek.txt
xcopy redirection
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.
Re: xcopy redirection
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
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.
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.
xcopy redirection
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).
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).
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: xcopy redirection
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
Or alternatively, robocopy: http://www.microsoft.com/download/en/de ... n&id=17657
xcopy redirection
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
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