In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (Drieux) writes:
>
>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:$!";
You are missing a '|' in there.
> my @response;
> while(<CMD>)
> {
> next if /^\s*$/; # space empty lines
> chomp; # end of line cleaner
> push(@response, $_);
> }
> close(CMD)
> [EMAIL PROTECTED];
No reason not to make that much simpler using backticks:
sub run_cmd
{
my $cmd = shift;
my $args = shift || '';
my @output = `$cmd $args 2>&1`;
$? < 0 and return "ERROR: problem running $cmd with $args: $!";
[ grep /\S/, map { chomp; $_ } @output ];
}
The only reason I left $cmd and $args separate is so the error
message could be identical; I think it would be better off
combining them into a single parameter.
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http//www.perlmedic.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>