...correct me if I'm wrong, but you still may have a problem.
Supplying the full path will get this additional script to run, but I don't think you're going to get the output from the command by grabbing the return value from system().
What you'll get stored in $output will simply be the exit code from your other script.
So here's how you can execute the external script and grab the output into a variable:
open (PROC "/path/to/perl myscript.pl |") || die "horribly";
@lines = <PROC>;
close PROC;
You may want to add other civilities, such as join()'ing the lines of output into one big scalar if that suits you. But this is one good way of grabbing output from a running process. Best of luck.
---v | [reply] [d/l] |
True ... true about not getting the output of the command, but
it will get the return code (system) with some
work. If you want capture STDOUT, you could also use the
backticks (as described in th qx/STRING/ section of perlop).
-derby
| [reply] |
Yeah, that was the next problem. At first I was using the backticks, but the problem was that the utility script took 20 or so minutes to run, and the backtick operator only returns after the child process has stopped running, so the operation timed out from the browser. I of course was using a nohup to keep the utility script running on the server, but the end user would see it as an error...
I implemented the open method after that, and it works beautifully :)
Final, working code (minus sensitive info):
...........................
#!/opt/perl5/bin/perl -w
use strict;
use CGI;
# set path, instead of putting it in the open statement
$ENV{'PATH'} = "/usr/bin:/opt/perl5/bin/:";
#location of product_gen.pl, plus arguments
my $gen_script = "/path/to/server/product_gen.pl -prfv";
# Create a new CGI object
my $cgi = new CGI;
# Output HTML header to browser
print $cgi->header('text/html');
print qq{<h4>script executing</h4>};
open(PRODUCT_GEN, "nohup perl $gen_script |") or die "Error: $!\n";
while (<PRODUCT_GEN>)
{
print $_, "<br>";
}
close(PRODUCT_GEN);
...........................
Thanks again for all the assistance!
higle | [reply] [d/l] [select] |