Reputation: 529
I have a task in windows scheduler that runs a batch file every minute. This batch file svn updates a number of folders then runs a perl script that forks off onto a number of other scripts.
Is there a command to enter in the batch file that will ensure all cmd output from running the task will be logged into a file with the date/time as the filename? e.g. if the program runs at 12:00 1st Jan 2014 it will be saved like: 1200-1-1-2014.log
Upvotes: 0
Views: 1130
Reputation: 26
In the batch file, you can add something like:
setlocal
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)
set Date=%Day%_%Month%_%Year%
perl [script name] >> [path to log]/%Date%.log
endlocal
I'm not sure about the syntax for the 'time' part of it but that should get you started on the right path.
Edit: found more info about getting the 'time' in this post:
How to get current datetime on Windows command line, in a suitable format for using in a filename?
Upvotes: 1
Reputation: 3484
Not as such, but using one of the excellent logging modules on CPAN you could write a short filer that echoes its input via a logger, and get the time stamps done for you.
Otherwise, you'll need to be using something like IPC::Open3 to control all of your output collection, and then use the logger in your main program.
Does windows even do pipes?
Upvotes: 0