开发者

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜