Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Executing perl script from perl scripts

by palette (Scribe)
on May 15, 2008 at 12:48 UTC ( #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.

print "1";
print "2";

require ""
ok("1","test 1");
require "";
ok("2","test 2");
Pls note I want require to execute, complete the validation and then the require 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, ''); # and check for system's return value! ok(1, 'Test 1'); system($^X, ''); ok(2, 'Test 1');

    If you want to process the script output, use

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

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

      Getting an error on executing should throw error telling that is errored. might not return a value '1'. What can be done in that case.
      If I want to run with one version of perl and the with another version of perl how can I do that
        system qw(perl5.8.8; system qw(perl5.10.0;
        /first_perl_location/bin/perl /second_perl_location/bin/perl
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?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2023-09-27 03:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found