I am scheduling a DOS batch script to run through Task Scheduler. Is there a way to configure the task/job to write all output (producing output using ECHO commands) to a log file? Can logging be configured within Task Scheduler (appears v1.0 is installed).
1 Answers
Use a starter batch that does the logging
You could either edit the script to output all to a file instead of the screen or you could just create a batch file to run the batch file and schedule the other batch file... (sorry, sounds confusing, I know).
Basically, assuming the batch file you run is called myscript.cmd create a batch file called myscript-logging.cmd. In that batch file put one command as follows:
myscript > c:\myscript.%date:~-4%%date:~4,2%%date:~7,2%.%time::=%.log 2>&1
The above should create a log file in the root of the C: drive with a name based on the date and time it was executed (so it never overwrites it and you have a log for each time the script is run).
Example
The example above, if the script were run at 10pm on June 22, 2010, should end up with a file name that looks like this:
myscript.20100622.220000.00.log
Format is this :
myscript.YYYYMMDD.HHMMSS.hundredths of a second.log
Caution: Watch your disk space!
CAUTION: this has the potential of filling up your hard drive as it never deletes a single log file and keeps on adding files.
So if you plan on using this for a long time you should invest additional effort into monitoring and maybe auto-cleaning your disk space.
- 1,540
- 4,498