user2429305
user2429305

Reputation: 1

Perl Script Runs Differently through Task Scheduler

I am running a perl script that is grabbing a file from an ftp server and then performing a system command.

When I run the task from the scheduler, it does not grab the file but it does perform the system command. Both are wrapped in an if statement so I know that the if statement is working properly.

I have checked the permissions already and the task is using the highest permissions. I also am running the task as an administrator. Now, the catch is that when I manually run the program, everything works properly. Why does it run properly when I manually run it but not when I run it through the scheduler?

Here is some of the code:

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

Upvotes: 0

Views: 857

Answers (1)

gangabass
gangabass

Reputation: 10666

Why do you think that the file is not downloaded? Do you have "get failed" error? I'm sure it's downloaded but not to the place you want.

When your script is executed from the Scheduler the current working directory usually is not the same you run it from command line. You can set your script working directory in the Task's properties or you can tell your script where to save downloaded file:

use FindBin qw($Bin);

....

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

Upvotes: 2

Related Questions