2010-07-02 63 views
2

我有一個perl.exe文件,我每十分鐘運行一次。我設置了Windows調度程序來運行它,它表示它是成功的,但文件中沒有輸出。當我單擊.exe時,它會將信息寫入輸出文件。當調度程序假定已經運行它時,文件中沒有任何內容。有沒有我可以寫入perl腳本的代碼,讓它每10分鐘運行一次?或者是否有人知道它可能無法正確執行的原因。這裏是我的腳本代碼:安排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"; 
+0

我們可以看到您在窗口調度程序中使用的命令嗎? – spinon 2010-07-02 21:07:00

+0

我沒有使用命令我剛剛選擇文件下的文件選擇選項 – shinjuo 2010-07-02 21:25:59

+0

'use strict;使用警告;' – Ether 2010-07-02 21:57:27

回答

1

假設你沒有從你的代碼中刪除的路徑和你沒有指定開始,在目錄中,提供了輸出文件,例如完整路徑

open OUTPUT, ">>J:/Project/Reports/output.txt" 
    or die "$0: open: $!"; 
+0

爲什麼它可以工作,雖然我自己點擊.exe文件,而不是當調度程序使用它時 – shinjuo 2010-07-02 21:26:49

+0

@shinjuo調度程序以系統根作爲當前目錄啓動任務。我假設你的代碼住在別的地方。 – 2010-07-02 21:36:54

+0

輸出文件與.exe及其所有文件一起位於相同的文件夾中 – shinjuo 2010-07-02 22:06:06

1

有兩件事情你應該做的:

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