Using Windows Server 2008, how do I go about capturing the output of a script that is being ran with the windows task scheduler?
I\'m testing a rather long custom pr
You can have a debug.cmd that calls yourscript.cmd
yourscript.cmd > logall.txt
you schedule debug.cmd instead of yourscript.cmd
You can write to a log file on the lines that you want to output like this:
@echo off
echo Debugging started >C:\logfile.txt
echo More stuff
echo Debugging stuff >>C:\logfile.txt
echo Hope this helps! >>C:\logfile.txt
This way you can choose which commands to output if you don't want to trawl through everything, just get what you need to see. The >
will output it to the file specified (creating the file if it doesn't exist and overwriting it if it does). The >>
will append to the file specified (creating the file if it doesn't exist but appending to the contents if it does).
Example how to run program and write stdout and stderr to file with timestamp:
cmd /c ""C:\Program Files (x86)\program.exe" -param fooo >> "c:\dir space\Log_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.txt" 2>&1"
Key part is to double quote whole part behind cmd /c
and inside it use double quotes as usual. Also note that date is locale dependent, this example works using US locale.