Scheduling a perl script

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";

Answers


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: $!";

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";

Need Your Help

Beans are null, rejected bean name by BeanNameUrlHandlerMapping

java spring spring-mvc servlets

I have problem with configuration of my App, every bean in application is null, all services are annotated by @Service, @Repository, @Controller or @Component. I noticed that beans are not created ...

How to create a global method in C# that can be called without prefixing the classname?

c# .net function static

If I want to make a function that can be called from every location in my project, I create static class with a static function, but I still have to refer to the function as Class.Method instead of