Click here to get back home

Problem with one perl script executing another, execution started by Apache httpd

 HomeNewsGroups | Search

comp.lang.perl.misc - PERL programming language 

get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Problem with one perl script executing another, execution started by Apache httpd Ted Byers 09-16-2008
Posted by Ted Byers on September 16, 2008, 10:39 am
Please log in for more thread options


Using the latest IndigoPerl, I have two scripts that do not behave
alike. Both are in the perl-bin directory of the Apache server
distributed with IndigoPerl.

The first one appended below works fine. It shows the output from a
perl script located in a directory tree completely outside the
directory tree for IndigoPerl, as well as a system command (this is
Windows XP). I get the expected output by providing the URL "http://
localhost/perl-bin/format_test.pl" to the browser.

The second one just hangs, displaying the initial text, but the script
appears to stop at the point where TedsMakeNewPortfolios.pl is
invoked. it is as if an attempt is made to run my scrpt, and control
is never returned to the main script. Yes, an association between
perl and the 'pl' extension has been created, and if I invoke
TedsMakeNewPortfolios.pl from the commandline (e.g. using
"TedsMakeNewPortfolios.pl 522"), it works flawlessly. So why isn't my
TedsMakeNewPortfolios.pl being executed?

The ONLY difference I can see is that my script takes a commandline
parameter and the printenv_segment.pl does not, but I don't see why
that would be significant. I will run a test, though, assigning "C:\
\yohan\PRODUCTION\MakeNewPortfoliosETF\TedsMakeNewPortfolios.pl
$id" to a local variable before trying to execute it, to see if that
makes a difference. But suggestions on how to get this to work would
be appreciated.

Thanks

Ted

======format_test.pl=================
#!c:/perl/bin/perl.exe
use strict;
use CGI qw/:standard/;
my $name = param('name');
my $id = param('id');

print <<"END";
Content-type: text/html

show/hide quoted text

show/hide quoted text
END

my $a = 0.0550001;
my $b = 150.3449;
my $c = 1158.435;
my $mc = -1158.435;
my $d = 100256147.258;

my $rv1a = sprintf("%.2f",$a);
my $rv1b = sprintf("%.2f",$b);
my $rv1c = sprintf("%.2f",$c);
my $rv1mc = sprintf("%.2f",$mc);
my $rv1d = sprintf("%.2f",$d);

my $rv2a = commify($rv1a);
my $rv2b = commify($rv1b);
my $rv2c = commify($rv1c);
my $rv2mc = commify($rv1mc);
my $rv2d = commify($rv1d);

show/hide quoted text

show/hide quoted text

my $output = `C:\ApacheAndPerl\Apache2\perl\printenv_segment.pl`;
show/hide quoted text
$output = `dir`;
show/hide quoted text

sub commify {
my $value = reverse $_[0];
$value =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $value;
}
=========portfolio_construction.pl===================

#!c:/perl/bin/perl.exe
use strict;
use CGI qw/:standard/;
my $name = param('name');
my $id = param('id');

print header,
start_html('Portfolio history construction'),
h1("Hello $name"),
p("id = $id");
print p("This may take a few minutes.");
print end_html;

my $output = `"C:\yohan\PRODUCTION\MakeNewPortfoliosETF\
\TedsMakeNewPortfolios.pl $id"`;

Posted by Ben Morrow on September 16, 2008, 11:12 am
Please log in for more thread options



show/hide quoted text

I would avoid invoking perl scripts like this. There are often issues
with command-line parameters: the windows association mechanism seems to
be rather flaky in this respect. Either invoke it as

`perl c:\...\TedsMakeNewPortfolios.pl 522`

or as

`$^X c:\...\TedsMakeNewPortfolios.pl 522`

if perl isn't in your PATH, or, better, simply call the script using
'do'.

show/hide quoted text

This is wrong. `` passes its contents to cmd /c, which handles any
further quoting itself. So effectively you are invoking

"C:\yohan\...\TedsMakeNewPortfolios.pl 522"

What happens if you type this (*including* the quotes) at the command
line?

Ben

--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
'Alcestis') [ flame, and falls out of sight. ] ben@morrow.me.uk

Posted by Ted Byers on September 16, 2008, 12:13 pm
Please log in for more thread options


Thanks Ben,

That was helpful.

show/hide quoted text
y
show/hide quoted text

Well, we're making progress. Before, none of the work that
TedsMakeNewPortfolios.pl handles was done. Now at least the data it
is supposed to produce is produced. I replaced my call with

`perl c:\...\TedsMakeNewPortfolios.pl $id`

Thanks. Now, I know what I need to do to finally fix this. You see,
the LAST thing that TedsMakeNewPortfolios.pl does is start an exe file
a colleague created, and IT starts another perl script that loads the
output data into a database (the language HE used does not have
support/drivers for accessing RDBMS - something that will change this
week). And THAT script is not getting executed.

The example for do in the documentation uses:

do 'stat.pl';

Will it handle command line arguments also. E.g.

do 'myscript.pl $argv[1]';


show/hide quoted text

This dies with a complain that it isn't recognized as a command,
program or batch file. That makes sense, now that I know the double
quotes would be passed on to cmd.

show/hide quoted text
gall
show/hide quoted text
no spoon.
show/hide quoted text
bursts into ]
show/hide quoted text
=A0 =A0 b...@morrow.me.uk

Thanks again

Ted

Posted by Ben Morrow on September 16, 2008, 12:27 pm
Please log in for more thread options



show/hide quoted text

Wow! I would want to see if you can avoid such a convoluted system of
invocations. At the very least, Perl scripts invoking Perl scripts can
be avoided.

show/hide quoted text

No. You can emulate it like

{
local @ARGV = ($id);
do 'script.pl';
}

but it would be better to rewrite the script to be used like this.
Ideally you would convert it into a .pm module you can 'use', which
exports a function that does all the real work; a half-way step would be
to wrap all the work in a function and then load the file with 'require'
or 'do'.

Ben

--
We do not stop playing because we grow old;
we grow old because we stop playing.
ben@morrow.me.uk

Posted by Ted Byers on September 16, 2008, 1:32 pm
Please log in for more thread options


Thanks Ben

show/hide quoted text
e,
show/hide quoted text
The perl invoking perl is a short term consequence of the real problem
we had to solve. We do some heavy duty number crunching, and this
crunching was much too slow to do either within our RDBMS or within
the Java based user interface(servlets + JSF). This is where the
compiled programs came in. We'll get the best performance when I get
time to implement some high performance C++ code, and this would
eliminate all need to the perl to handle data at all (since the C++
program would get input data from, and put output data to, the RDBMS
directly) and perl would then be just the glue that gets the right
program executed on demand, but there's no time for that yet. Anyway,
we needed a way to invoke these programs on demand from our web
interface. CGI on Tomcat wouldn't do it, and neither would our JSF
pages. As time allows, I will be cleaning up and simplifying the
system of invocations, but the boss wants to see it in action RSN.

show/hide quoted text

Thanks. Good to know.

Ted

show/hide quoted text
;
show/hide quoted text


Similar ThreadsPosted
speeding up perl script execution under apache October 29, 2004, 5:29 pm
mod_perl in Apache httpd October 16, 2008, 12:17 pm
How to make input user and password in perl script started on web? May 29, 2008, 4:15 pm
Executing cmd from perl script September 8, 2004, 9:49 pm
Executing awk from perl script March 24, 2007, 12:55 pm
crontab for executing perl script August 3, 2005, 3:56 pm
executing perl script without .pl extension August 2, 2006, 10:24 am
Issue in executing more than one perl script from Single perl script November 1, 2007, 2:52 am
Getting started in PXPerl, i.e how to run a script? July 20, 2006, 10:12 am
Re: Can I monitor the execution of a perl script September 2, 2006, 8:59 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap
Privacy Policy