views:

50

answers:

2

I have a perl .exe file that I was to run every ten minutes. I have set up the windows scheduler to run it and it says that it is successful but there is no output in the file. When I click the .exe myself it writes information to an output file. When the scheduler supposedly has ran it there is nothing in the file. Is there a code I can write in to the perl script to make it run every ten minutes on its own? Or does anyone know a reason why it might not be executing properly. Here is my script code:

#!/usr/bin/perl -w
use LWP::Simple;
$now_string = localtime;

my $html = get("http://www.spc.noaa.gov/climo/reports/last3hours.html")
    or die "Could not fetch NWS page.";
$html =~ m{(Hail Reports.*)Wind Reports}s || die;
my $hail = $1;
open OUTPUT, ">>output.txt";
print OUTPUT ("\n\t$now_string\n$hail\n");
close OUTPUT;
print "$hail\n";
+1  A: 

Assuming you didn't remove the path from your code and that you're not specifying a start-in directory, provide a full path for the output file, e.g.,

open OUTPUT, ">>J:/Project/Reports/output.txt"
  or die "$0: open: $!";
Greg Bacon
why would it work though when I click the .exe file myself and not when the scheduler uses it
shinjuo
@shinjuo The scheduler starts tasks with the system root as the current directory. I assume your code lives somewhere else.
Greg Bacon
the output file is located in the same folder along with the .exe and all of its files
shinjuo
Okay so I wrote in the use warnings and use scripts; I also gave the directory like you said. Then I redid the task and now it works. If it was this than thanks.
shinjuo
+2  A: 

There are 2 things you should do:

  1. Specify the path in the program
  2. Make sure the permissions to the file are writable by the scheduler

Code:

#!/usr/bin/perl -w

use LWP::Simple;
use strict;                                           # make sure you write good code

   my $now_string = localtime;

   my $html = get("http://www.spc.noaa.gov/climo/reports/last3hours.html")
              or die "Could not fetch NWS page.";
   my ($hail) = $html =~ m{(Hail Reports.*)Wind Reports}s or die;  # combine your lines in one

   my $file = "C:\Path\output.txt";                   # use full qualified path
   open OUTPUT, ">>$file";
      print OUTPUT ("\n\t$now_string\n$hail\n");
   close OUTPUT;

   print "$hail\n";
vol7ron