Windows – Scheduling a Perl script with output redirection

perlscheduled-taskwindows

I'm trying to schedule a Perl script to be run from the Windows task scheduler and have the output be redirected to a text file. This seems straight forward, but it's not following the redirection, and instead just being printed in a console window.

I've tried various methods, and I'm assuming it's either not possible, or I'm doing something stupid.

I've tried with and without quotes to no avail. The script either doesn't run, or Windows just ignores the redirection. Currently I'm using something like:

perl %Scripts%\Perl\network_information.pl > %Dropbox%\Random\network_information_<machinename>.pl

Which obviously works in a command window, and runs in a scheduled task, but with the redirection being completely ignored. I've tried it with quotes as well, and it just continues to ignore the output redirection.

I'm going to run this from multiple machines, so I'd like it to work from a scheduled task. I'm assuming it would probably work a batch file and then scheduling the batch, but I'd like to avoid that if possible. Any help would be appreciated.

Best Answer

Put the perl command in a batch file and then call the batch file from Task Scheduler

@echo off
set Dropbox=abc
perl.exe myfile.pl > %Dropbox% 2>&1