perlscheduled-taskswindows-task-scheduleroutput-redirect

Output redirects are not working running Perl program via Windows Task Scheduler


I have Perl script configured to run periodically via Windows Task Scheduler.

Action: Start a program
Program: C:\Perl64\bin\perl.exe
Add arguments: script.pl config.json > output.txt 2>&1
           or: script.pl config.json 2>&1 > output.txt
Start in: c:\path\to\scriptPL\

The program runs, but it gets either > or 2>&1 in $ARGV[1], instead of redirecting outputs. When running from the command prompt output redirects work.

What am I missing?

enter image description here enter image description here


Solution

  • Output redirection may or may not work with the Task Scheduler. The workaround is to run your desired command (including output redirection) inside a batch file, and to call the batch file from Task Scheduler.

    script.bat
    ----------
    C:\Perl64\bin\perl.exe script.pl config.json > output.txt 2>&1