Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Executing perl script from perl scripts

by palette (Scribe)
on May 15, 2008 at 12:48 UTC ( [id://686719]=perlquestion: print w/replies, xml ) Need Help??

palette has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a number of perl scripts that execute from the crontab.
I want to write a test script that executes the perl files.
After executing each perl files I have to validate the database. So I have to add the test case for those validation.
Now I have to execute the next perl script in the same test script and validate that as well.
So it's sequential execution of some process scripts that I have to validate. But after each process script I will be doing some validation.
How can I do this in perl.
Does 'require' works fine for this.

example 1.pl
print "1";

2.pl
print "2";


test.t
require "1.pl"
ok("1","test 1");
require "2.pl";
ok("2","test 2");
Pls note I want require 1.pl to execute, complete the validation and then the require 2.pl should execute.
  • Comment on Executing perl script from perl scripts

Replies are listed 'Best First'.
Re: Executing perl script from perl scripts
by moritz (Cardinal) on May 15, 2008 at 13:11 UTC
    In a test file you should call the scripts in the same what that cron does, which is through a system call or the shell.

    You can do that in perl like this:

    system($^X, '1.pl'); # and check for system's return value! ok(1, 'Test 1'); system($^X, '2.pl'); ok(2, 'Test 1');

    If you want to process the script output, use

    my $res = qx($^X 1.pl); chomp $res; is($res, 1, '1.pl worked'); $res = qx($^X 2.pl); chomp $res; is($res, 2, '2.pl worked');

    ($^X is the path of the current perl interepreter)

      Getting an error on executing 1.pl should throw error telling that 1.pl is errored. 1.pl might not return a value '1'. What can be done in that case.
      If I want to run 1.pl with one version of perl and the 2.pl with another version of perl how can I do that
        system qw(perl5.8.8 1.pl); system qw(perl5.10.0 2.pl);
        /first_perl_location/bin/perl 1.pl /second_perl_location/bin/perl 2.pl
        Cheers,
        Rob
Re: Executing perl script from perl scripts
by Fletch (Bishop) on May 15, 2008 at 13:10 UTC

    So what happened when you tried that? Aside from the nit that I'd say you probably want to use do not require, your sample code (though unfortunately berefit of <code></code> tags) should do what you described.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Executing perl script from perl scripts
by apl (Monsignor) on May 15, 2008 at 13:11 UTC
Is the Pope Catholic? - was Re: Executing perl script from perl scripts
by Narveson (Chaplain) on May 16, 2008 at 16:24 UTC

    Good idea to start with a simple test, but these tests are too simple.

    ok("1","test 1"); tests whether "1" is a true value. If you ever find this test failing, please let me know.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://686719]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-20 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found