perlwindows-task-schedulerplack

Run perl Plackup script from Scheduled Task


How can I call a script with that preceding argument before the script path using Task Scheduler or a batch file? plackup E:\Mojolicious_server.pl

So I have multiple Mojolicious applications. I have bundled them all into a psgi server using plack.

My plack script looks like this...

use Plack::Builder;
use lib 'push_the_button/lib';
use lib 'Phone_Book/lib';

use Mojo::Server::PSGI;
use Plack::Session::Store;
use Data::Dumper;
use File::Basename;

my $current_directory = dirname(__FILE__);

my $push_the_button, $phone_book;


{
  my $server_1 = Mojo::Server::PSGI->new;
  $server_1->load_app($current_directory.'/Phone_Book/script/application');
  $phone_book = sub { $server_1->run(@_) }
}

{
  my $server_2 = Mojo::Server::PSGI->new;
  $server_2->load_app($current_directory.'/push_the_button/script/push_the_button.pl');
  $push_the_button = sub { $server_2->run(@_) }
}

builder {

  mount "/phone_book" => builder {$phone_book};
  mount "/push_the_button" => builder {$push_the_button};
};

Now I want to run this as a scheduled task at system startup.

to run this script normally, I would go to cmd pushd c:\strawberry\perl\bin

Then I would run this command

plackup E:/Mojolicious_Server.pl

My issue seems to be that plackup portion. I have tried adding plackup E:/Mojolicious_Server.pl to the Arguments portion. I have also tried adding plackup to the arguments portion and E:/Mojolicious_Server.pl in the start in portion. Of course C:\strawberry\perl\bin\perl.exe is the Program to start.

Once I tried all the variations I could think of (including variations on double and single quotes), I wrote a very simple batch file to run (even just in the terminal for testing). It looks like this.

@echo off

call "C:\Strawberry\perl\bin\perl.exe" "plackup E:\Mojolicious_Server.pl"

Which says "Can't open perl script".

I went ahead and tried another route using another perl script to execute my command...

#! C:\strawberry\perl\bin\perl.exe

`plackup E:\\Mojolicious_Server.pl`;

This at least completes successfully in the Task Scheduler, doesn't actually do anything though...

Just as a last resort (obviously wouldn't work), I added plackup E:\\Mojolicious_Server.pl; at the end of my Mojolicious_Server.pl script and run that script. Didn't work as I expected (calling a script thats already running).

This seems like it should be very easy, I'm sorry if I'm missing something simple. Any notion in the right direction would be appreciated.

Also I am only doing it this way because I am strictly on a windows environment. If there is a better way, again, please just a nudge in the right direction.


Solution

  • As stated in the comments of the question, all it takes is to invoke the sequence plackup E:/Mojolicious_Server.pl making sure that you add the full path to the plackup script. In the case of @gregnnylf94, it was:

    c:\strawberry\perl\site\bin\plackup E:\Mojolicious_server.pl
    

    This is so because cron jobs do not have the same context as shell ones. The most frequent problem comes from the PATH variable that is key to finding what you want to execute.

    This is true in Windows and Linux systems alike.