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.


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
  • Yeah, that was the route I was going to have to take if I couldn't find any other way to get it to work. I'm trying to avoid this, but it may be my only option (minus having the script write to the file directly) – Matthew May 6 '11 at 15:38

I've never had much luck with output redirection in Windows scheduled tasks (and I could never be bothered to find out why) -- My advice is to cheat.

Take a look at this page, which talks about perl's open() function -- about halfway down they show you how to dup, redirect & restore STDOUT (STDERR, STDIN, etc.) from within perl using open().

  • I'd hardly call using the language's built-in functions "cheating" :-) – mfinni May 6 '11 at 16:17
  • "Cheating" compared to leaving the script alone (so it can still run from the command line) and just doing >filename 2>&1 like you would in a crontab :-) – voretaq7 May 6 '11 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.