Click here to get back home

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

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   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
Get Chitika Premium
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

<HTML><HEAD>
<TITLE>Arrays</TITLE>
</HEAD>

<BODY>
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);

print "a\t$a\t$rv1a\t$$rv2a<br>\n";
print "b\t$b\t$rv1b\t$$rv2b<br>\n";
print "c\t$c\t$rv1c\t$$rv2c<br>\n";
print "mc\t$mc\t$rv1mc\t$$rv2mc<br>\n";
print "d\t$d\t$rv1d\t$$rv2d<br>\n";

print "<br><p>name:\t$name<br>\n";
print "<br><p>id:\t$id<br>\n";

my $output = `C:\ApacheAndPerl\Apache2\perl\printenv_segment.pl`;
print "$output<br><br><br><br>";
$output = `dir`;
print '<PRE>';
print "$output<br>";
print '</PRE>';
print '</BODY></HTML>';

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



> 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?

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'.

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

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.

>
>
>
> > Using the latest IndigoPerl, I have two scripts that do not behave
> > alike. =A0Both are in the perl-bin directory of the Apache server
> > distributed with IndigoPerl.
>
> > The first one appended below works fine. =A0It 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). =A0I 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. =A0it is as if an attempt is made to run my scrpt, and control
> > is never returned to the main script. =A0Yes, 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. =A0So why isn't m=
y
> > TedsMakeNewPortfolios.pl being executed?
>
> 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
>
> =A0 =A0 `perl c:\...\TedsMakeNewPortfolios.pl 522`
>
> or as
>
> =A0 =A0 `$^X c:\...\TedsMakeNewPortfolios.pl 522`
>
> if perl isn't in your PATH, or, better, simply call the script using
> 'do'.
>

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]';


> > my $output =3D `"C:\yohan\PRODUCTION\MakeNewPortfoliosETF\
> > \TedsMakeNewPortfolios.pl $id"`;
>
> This is wrong. `` passes its contents to cmd /c, which handles any
> further quoting itself. So effectively you are invoking
>
> =A0 =A0 "C:\yohan\...\TedsMakeNewPortfolios.pl 522"
>
> What happens if you type this (*including* the quotes) at the command
> line?
>

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.

> Ben
>
> --
> Heracles: Vulture! Here's a titbit for you / A few dried molecules of the=
gall
> =A0 =A0From the liver of a friend of yours. / Excuse the arrow but I have=
no spoon.
> (Ted Hughes, =A0 =A0 =A0 =A0[ Heracles shoots Vulture with arrow. Vulture=
bursts into ]
> =A0'Alcestis') =A0 =A0 =A0 =A0[ flame, and falls out of sight. ] =A0 =A0 =
=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



> >
> > if perl isn't in your PATH, or, better, simply call the script using
> > 'do'.
>
> 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.

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.

> 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]';

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

>
>
>
>
> > > if perl isn't in your PATH, or, better, simply call the script using
> > > 'do'.
>
> > Well, we're making progress. =A0Before, none of the work that
> > TedsMakeNewPortfolios.pl handles was done. =A0Now at least the data it
> > is supposed to produce is produced. =A0I replaced my call with
>
> > =A0 =A0 `perl c:\...\TedsMakeNewPortfolios.pl $id`
>
> > Thanks. =A0Now, I know what I need to do to finally fix this. =A0You se=
e,
> > 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). =A0And THAT script is not getting executed.
>
> 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.
>
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.

> > The example for do in the documentation uses:
>
> > =A0 =A0 do 'stat.pl';
>
> > Will it handle command line arguments also. =A0E.g.
>
> > do 'myscript.pl $argv[1]';
>
> No. You can emulate it like
>
> =A0 =A0 {
> =A0 =A0 =A0 =A0 local @ARGV =3D ($id);
> =A0 =A0 =A0 =A0 do 'script.pl';
> =A0 =A0 }
>
> 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'.
>

Thanks. Good to know.

Ted

> Ben
>
> --
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0We do not stop playing because we grow old=
;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 we grow old because we stop playing.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 b...@morrow.me.uk


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
Re: Can I monitor the execution of a perl script September 2, 2006, 8:59 am
Can I monitor the execution of a perl script September 1, 2006, 5:50 pm
Issue in executing more than one perl script from Single perl script November 1, 2007, 2:52 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap