代码之家  ›  专栏  ›  技术社区  ›  shinjuo

调度Perl脚本

  •  2
  • shinjuo  · 技术社区  · 14 年前

    我有一个Perl.exe文件,每十分钟运行一次。我已经设置了Windows调度程序来运行它,它说它是成功的,但是文件中没有输出。当我自己单击.exe时,它会将信息写入输出文件。当调度程序运行它时,文件中没有任何内容。是否有一个代码可以写入Perl脚本,使其每十分钟独立运行一次?或者有人知道它可能无法正常执行的原因吗?这是我的脚本代码:

    #!/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";
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Greg Bacon    14 年前

    假设您没有从代码中删除路径,并且没有在目录中指定起始位置,请为输出文件提供完整的路径, 例如 ,

    open OUTPUT, ">>J:/Project/Reports/output.txt"
      or die "$0: open: $!";
    
        2
  •  1
  •   vol7ron    14 年前

    你应该做两件事:

    1. 指定程序中的路径
    2. 确保计划程序对该文件的权限是可写的

    代码:

    #!/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";