How do I capture the output of a script if it is being ran by the task scheduler?

前端 未结 9 713
旧巷少年郎
旧巷少年郎 2020-12-02 08:37

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

相关标签:
9条回答
  • 2020-12-02 09:25

    You can have a debug.cmd that calls yourscript.cmd

    yourscript.cmd > logall.txt
    

    you schedule debug.cmd instead of yourscript.cmd

    0 讨论(0)
  • 2020-12-02 09:25

    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).

    0 讨论(0)
  • 2020-12-02 09:26

    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.

    0 讨论(0)
提交回复
热议问题