Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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
share|improve this answer
    
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().

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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