Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Executing another script from a CGI

by higle (Chaplain)
on Jul 24, 2002 at 20:32 UTC ( [id://185017]=note: print w/replies, xml ) Need Help??


in reply to Re: Executing another script from a CGI
in thread Executing another script from a CGI

Thanks!

Wow, I didn't even think to check that. I thought we had our box configured with Perl in the path for CGI processes, but I guess not.

My philosophy has always been, "Check the simplest things first." Looks like I should follow my own advice...

  higle
  • Comment on Re: Re: Executing another script from a CGI

Replies are listed 'Best First'.
Re: Re: Re: Executing another script from a CGI
by agentv (Friar) on Jul 24, 2002 at 21:34 UTC
    ...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

      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

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://185017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found