man1ac
Goto Top

xcopy Fehlercode umleiten

Hallo zusammen!

Ich habe eine Batch-Datei die über Mail an bestimmte User im Netzwerk gesendet wird. Sie kopiert einen bestimmten Ordern von einem Serven auf die Clients. Sieht im Prinzip so aus:

xcopy quelle ziel >> logfile

Wenn aber Fehler beim Kopieren auftreten wird der eigentliche (interessante) Teil der Fehlermeldung am Bildschirm des ausführenden Clients ausgegeben (zB.: "Datei konnte nicht gefunden werden.")

Wie veranlasse ich das Batch-File dazu, dass der Fehlertext auch in das logfile übernommen wird?

Content-Key: 6795

Url: https://administrator.de/contentid/6795

Ausgedruckt am: 28.03.2024 um 08:03 Uhr

Mitglied: linkit
linkit 11.02.2005 um 17:07:29 Uhr
Goto Top
Zu xcopy ist mir hier keine Funktion bekannt. Du kannst aber von Microsoft ebenso robocopy.exe nutzen, das mit den Resource Kits ausgeliefert wird. Zu finden unter: http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff- ...

Mit Robocopy kannst du genauso einfach wie mit xcopy kopieren. Es ist aber ein viel mächtigeres Werkzeug als xcopy. Auch Logdateien, Profile etc. kannst du damit erstellen.

Zur datei robocopy wird auch noch eine Hilfedatei im Wordformat mitgeliefert, die alles genau beschreibt.


Zum Loggen:


During a run, Robocopy creates an Output Log that comprises a Job Header detailing the command line arguments used for the job, a list of files and directories processed during the job, and a Job Summary that shows totals copied, etc. By default, Output Log is written to the command prompt. This output can be redirected to a file, either by using the standard command-line operators (> or >>), or by using one of the command-line options:
? /LOG:file redirects output to the specified file, overwriting the file if it already exists.
? /LOG+:file redirects output to the specified file, appending it to the file if it already exists.
You can also use /TEE in conjunction with one of the above options. This causes Robocopy to log its output to both the command prompt (for visual progress monitoring) and the specified file (for a permanent record of the Robocopy run).

Aside from error reporting and retries, Robocopy produces one line of output per source file or directory. Lines for directories show the number of files in that directory specified for copying (where known) and the full path of the directory. Lines for files indicate the name of the file, the size of the file, and what was done with the file.

One line is also generated for each Mismatched file and directory and each Extra file and directory in the destination. Lines for Extra files include the full path and name of the file.
By default, the only Extra files reported are those that match files specified for copying on the command line. In most cases, this is more efficient. For example, if you are refreshing CPP files, you probably do not need information about TXT files in the destination. If you want a list of all Extra files in the destination, regardless of their type, use the /X switch.
No output is produced for skipped files. To obtain a verbose listing that shows all source files specified for copying on the command line, including skipped files, use the /V switch.
Robocopy provides copy progress information (% copied) by default. You can use the /NP switch to suppress the display of progress information. This can be useful when output is redirected to a file.
To see the start time of each file copy and the estimated time of completion based on the observed throughput of previous copies, use the /ETA switch. Times are displayed after the file name in the format HH:MM ? > HH:MM (start ? > finish).
Finally, to obtain only a list of the files that would be copied (without actually copying them), use the /L switch.

This default contents of the output log can be modified using the following command line switches :
? /TS displays the file timestamps for every file processed.
? /FP replaces simple file names with full file pathnames in the output.
? /NS (No Sizes) suppresses output of file sizes.
? /NC (No Classes) suppresses output of file class ?Text Tags? (see below).
? /NDL (No Directory List) suppresses output of the directory list. When /NDL is used, full pathnames of processed files are logged instead of the simple file name, so that problems can be pinpointed. Because of this, note that log files can actually increase in size if /NDL is used. Directories deleted by /PURGE (or which would be deleted if /L was omitted, if /PURGE and /L were both used) are always logged even if /NDL is used.
? /NFL (No File List) suppresses output of files processed. File copy failures are still logged even if /NFL is used, so that problems can be isolated. Files deleted by /PURGE (or which would be deleted if /L was omitted, if /PURGE and /L were both used) are always logged even if /NFL is used.
? /NJH (No Job Header) suppresses output of the job header.
? /NJS (No Job Summary) suppresses output of the job summary.
Combinations of these switches allow quite a bit of flexibility in terms of what is logged. For example, you could use /NDL /NC /NS to produce a list of just the full pathnames of files that were processed during the run, or you could use /NDL /NFL to produce just the summary report for the run (see ?Run Summary? below).
Mitglied: fritzo
fritzo 11.02.2005 um 20:08:31 Uhr
Goto Top
Hi,

Du kannst den error output jedes Befehls umleiten mit "2> file". Wenn Du den error output im selben File haben willst wie den normalen, dann nimmst Du "2>&1"

Kurzer Tip noch: Vars werden in % inkludiert, damit sie geparst werden können. Bei Befehlen wie "for /f %a" mußt Du in Batches zwei % angeben, sonst funktioniert es nicht.

Also:
"xcopy %quelle% %ziel% >> %logfile% 2> %logfile%"

oder einfacher mit:
"xcopy %quelle% %ziel% >> %logfile% 2>&1"

Grüße,
fritzo
Mitglied: man1ac
man1ac 15.02.2005 um 10:58:11 Uhr
Goto Top
@fritzo: Danke für den Tip mit der Standardfehlerumleitung; hat alles bestens geklappt.

@linkit: Vielleicht sollte ich das mit robocopy auch mal versuchen. Allerdings muss dann ja das Tool auch auf den Clients installiert werden. Deshalb werd ich wohl - solange xcopy reicht - damit arbeiten.

Grüße