Question:
How to create a log file in MS-DOS?
other_guy
2007-09-07 14:07:37 UTC
I have a batch file to copy some files from computer A to computer B using the XCOPY command that runs every night. The problem is, if the XCOPY command fails (because for instance computer B was turned off), I would never know. So far I've been checking manually folder by folder everyday to see if the batch file worked OK but that job is getting tiresome. I want to add to my batch file some sort of log recording capabilities. I know I can use ERRORLEVEL to check if XCOPY was successful but how can I make the batch file to send (or copy) this information in a log file using timestamps?
Five answers:
blackfangz
2007-09-07 14:16:17 UTC
You can redirect the screen output to a file by using the redirection indicator.



xcopy a:\ b:\ >c:\log.txt



A single > over writes a >> appends.



You might want to try xxcopy... a free program. It works a LOT slicker..
cairns
2016-12-15 09:09:43 UTC
Xcopy Log File
thomasjcollins
2007-09-11 01:58:22 UTC
Another suggestion would be to use ROBOCOPY instead of XCOPY. Robocopy is included with Vista, it can also be downloaded from microsoft (part of the server 2003 resource kit)



ROBOCOPY /w:300 /TBD /S /LOG+:



this will try to copy every 5 minutes, also if the network folder is not available it will wait until it comes online. Each time it runs, it will append what happened to
anonymous
2007-09-07 16:37:09 UTC
You can redirect the standard output stream of any program by appending



> log.txt



to the end of the command. But in your case, you want to capture the standard error stream as well as standard output. Modern versions of the DOS command interpreter allow the Bourne Shell syntax



someCommand > log.txt 2> err.txt



which sends the command's standard output to log.txt and its standard error stream to err.txt. You can also add the magic token 2>&1, as in



someCommand > logerr.txt 2>&1



which duplicates standard error (stream 2) onto standard output (stream 1) if you want them both captured together.



The >> variation allows appending instead of starting a new file. So if you had a log file which you wanted to span several days, you would do



someCommand >> logerr.txt 2>&1
anonymous
2016-03-13 07:09:26 UTC
actually enter "time /t" for date "date /t" this will just bring up the time and date without prompting you to enter a new time or date


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...