On 07/28/11 15:52,
wrote:
> Hi,
>
> I'm using Perl 5.10.1 on Ubuntu Linux 11.04. I want to run a Perl
> script B from within Perl script A. I can run Perl script B fine from
> the bash shell, but when I try and run it within Perl script A, it
> fails to execute with a "No such file or directory " error. I'm
> hoping someone might have some advice about what I'm overlooking.
>
> Here's how I create and spawn Perl script B ...
>
>
> my $cmd = "perl /opt/scripts/selenium/generate_test_suite.pl \"$
> {project} USA Tests - ${module}\" \"$destTestDir\" \"$testSuiteFile\"
> ";
You probably don't need 'perl' there. If you do, then
generate_test_suite.pl could be fixed, or you *should* use
the full path to perl.
You could also use qq, to eliminate escaping the double quotes and
there's no need for the braces either.
my $cmd = qq{ /opt/scripts/selenium/generate_test_suite.pl "$project USA
Tests - $module" "$destTestDir" "$testSuiteFile" };
> runShellCommand( $cmd );
>
> sub runShellCommand {
> my $cmd = shift;
> print "running command $cmd ...\n";
> open(F, "$cmd") or die "Can't execute command \"$cmd\": $!";
open( f, "$cmd |" ) or die "Can't execute command \"$cmd\": $!";
perldoc -f open
perldoc perlopentut
> while (<F>) {
> print;
> }
> close(F);
> print "done.\n\n";
> }
Another option is backticks:
my $out = `$cmd`;
print "$out\ndone\n\n";
If you want to do something if generate_test_suite.pl dies or exits with
an error, see perldoc IPC::Open3.