2013-05-28 113 views
0

我正在运行一个perl脚本,它从ftp服务器获取文件,然后执行系统命令。Perl脚本通过任务计划程序运行不同

当我从调度程序运行任务时,它不抓取文件,但它执行系统命令。两者都包含在if语句中,所以我知道if语句正常工作。

我已经检查了权限并且任务使用的权限最高。我也以管理员身份执行任务。现在,当我手动运行程序时,一切正常。为什么当我手动运行它时运行正常,但当我通过调度程序运行时运行却不正常?

下面是一些代码:

if ($size_ftp == $size_local) { 
      print "Files are the same...\n"; 
      $ftp->quit; 
      print "FTP has quit!\n"; 
     } else { 
      print "Files are not the same...begin download!\n"; 
      $ftp->get($file_ftp) or die "get failed ", $ftp->message; 
      print "Download complete...\n"; 
      $ftp->quit; 
      print "FTP has quit!\n"; 
      my $Archive_file = Archive::Extract -> new(archive => $file_dir); 
      print "File extraction identified...\n"; 
      $Archive_file -> extract(to => $extract_here); 
      print "File extracted...\n"; 
      system('call "C:\QMSEDX.exe"'); 
      print "System EDX call completed!\n"; 
    } 
+3

我不知道答案,但Unix的家伙谁使用cron抱怨这[全部](http://stackoverflow.com/questions/2046570)[the](http://stackoverflow.com/questions/13204/)[时间](http://stackoverflow.com/questions/ 780072)。 – mob

回答

2

为什么您认为该文件没有下载?你有没有“失败”错误?我确定它已下载,但不是你想要的地方。

从调度程序执行脚本时,当前工作目录通常与命令行运行的目录不同。您可以设置脚本的工作目录任务的属性或者你可以告诉你的脚本,以保存下载文件

use FindBin qw($Bin); 

.... 

$ftp->get($file_ftp, "$Bin/$file_ftp") or die "get failed ", $ftp->message; 
+1

是的,谢谢。我用下面的代码来改变目录,现在它工作正常: 使用File :: chdir; my $ dir = getcwd; print“原来的cwd是$ dir \ n”; $ CWD ='path/here /'; $ dir = getcwd; – user2429305

+0

接受这个答案! –

相关问题