On Dec 18, 2003, at 10:12 PM, Tushar Gokhale wrote:
How do I call another perl script from my current perl script? I'm working
on one perl testing harness, currently my "bin/run.pl" has a control and
now I want to call script files one by one from "tests/" folder. I also
want to pass an argument to the test script file. Once the file is executed
from "tests" folder i want the control to come back to my run.pl file.
there are several ways to try this, my pet favorite gag is
sub run_cmd { my ($cmd, $args) = @_; return "ERROR: no command" unless $cmd; $args ||=''; # so that it is initialized open(CMD, "$cmd $args 2>&1") or return "ERROR: problem running $cmd with $args:$!";
my @response; while(<CMD>) { next if /^\s*$/; # space empty lines chomp; # end of line cleaner push(@response, $_); } close(CMD) [EMAIL PROTECTED]; }
this I could call inside of a loop like say
opendir(DIR, $test_dir) or die "unable to open $test_dir:$!"; my @allfiles = grep { $_ !~ /^\./ } readdir(DIR); close(DIR) foreach my $file (@allfiles) { next unless ( <execute_condition> );
my $response = run_cmd($file); if ( ref($response) eq 'ARRAY') { deal_with_response_array($file, $response) } else { print "$file had problem: $response\n"; } }
but personally I like the idea of growing out my test cases in Perl Modules so that I can dish them up with cool dispatching solutions....
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>