php won't exec perl module

Problems with the Windows version of XAMPP, questions, comments, and anything related.

php won't exec perl module

Postby ebohatch » 29. June 2010 20:48

I have a php module with the following:
<?php
echo "
<HTML>
<HEAD>
<TITLE>web Gallery</TITLE>
</HEAD>
<BODY>
<P>
web gallery
";
exec("perl simple.pl");
echo "
</p>
</BODY>
</HTML>
";
?>

It never executes the perl program simple.pl
This is it:

#!/usr/bin/perl
use strict;
print "This is version\n";


If I run CMD it runs the program just fine??


I have a Win 7 system running following:
Apache/2.2.14 (Win32)
DAV/2 mod_ssl/2.2.14
OpenSSL/0.9.8l mod_autoindex_color
PHP/5.3.1 mod_apreq2-20090110/2.7.1
mod_perl/2.0.4
Perl/v5.10.1

To the begining of the PATH variable I haave added
C:\xampp\perl\bin;C:\Program Files\ImageMagick-6.6.2-Q16;

These were installed with Xampp.

Any help will be appreciated, I have some older php and perl modules that used to work (2006) with older Apache/PHP/Perl versions. but I am just getting back to them now.
ebohatch
 
Posts: 11
Joined: 09. February 2010 18:52

Re: php won't exec perl module

Postby Altrea » 30. June 2010 01:59

ebohatch wrote:It never executes the perl program simple.pl
This is it:

#!/usr/bin/perl
use strict;
print "This is version\n";


Obviously you are running a Windows based system. So please explain why do you use a linux path shebang?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php won't exec perl module

Postby ebohatch » 30. June 2010 03:15

The shebang line is for unix/linux (which the host where the main website is running).

In the windows environment it is ignored, that is why the perl/bin must be in the PATH environment variable.
ebohatch
 
Posts: 11
Joined: 09. February 2010 18:52

Re: php won't exec perl module

Postby JonB » 30. June 2010 04:03

ebohatch - well, sorta, ahhh, ummm - OK -- you are wrong again, LOL.

Because XAMPP doesn't 'do PATH'. I have several Perl apps running on my XAMPP server and no sign of any references to Perl in the PATH. XAMPP doesn't touch the registry or the path, other than to register the XAMPP installer. ActiveStates Perl, on the other hand, DOES rely on the path/environment. That is because Perl can execute without a host server, unlike PHP.

You are somewhat right in that a shebang line is not always needed in XAMPP - but that is because of Apache, specifically the perl.conf file found in apache/conf/extra - BUT Only when mod_perl is running (it virtualizes Perl). Just now, as a test, I trashed the shebang line in my Forum, and it returns a 500 ISE
"The server encountered an internal error and was unable to complete your request.

Error message:
couldn't create child process: 720003: YaBB.pl
"
Putting back the shebang (#!C:/xampp/perl/bin/perl.exe) fixes my Forum - enough said?

So fix the ugly shebang, and then see waht happens :wink:

Is the idea that the output will be returned to the PHP script and output inside the PHP process?

Cheers;
:cool:

found this discussion:
http://www.php.net/manual/en/function.shell-exec.php
http://php.net/manual/en/ref.exec.php
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: php won't exec perl module

Postby ebohatch » 30. June 2010 14:10

I assumed the PATH was used. Last time I had Apache, etc. on my PC was with the separate module implemented and I was using Active state. Now it is so much easier to setup[ via xampp.

BUT I followed you direction and still no results.
Removed the shebang line completely, nothing.
put in the shebang ling #!C:/xampp/perl/bin, nothing
changed to #!C:/xampp/perl/bin/perl nothing
changed to #!C:/xampp/perl/bin/perl.exe nothing

read the discussion on shell_exec. tried it nothing
re-read (3rd time) the discussion exec still nothing

uncommented perl settings line
Include "conf/extra/perl.conf" nothing

checked that all of my virtual hosts had Execgi


Changed my php script to the following:
<?php

echo "
<HTML>
<HEAD>
<TITLE>pl test</TITLE>
</HEAD>
<BODY>
<P>
pl test<br>
";
exec("perl -v");

echo "
</p>
</BODY>
</HTML>
";

?>

I should now be getting the perl version info, when I run as a command line I get this info fine.

I even put the complete path in the exec line:
exec("#!C:/xampp/perl/bin/perl -v");

nothing

if I change the line to:
exec("convert input.jpg -thumbnail 100x100 output.jpg");

it runs the ImageMagick module and creates the thumbnail just fine. ergo the exec function is working

when I go to the command line and run perl hello.pl or perl -v it works fine
hello.pl:
#!C:/xampp/perl/bin
print "Hello World\n";


what else can I check????
ebohatch
 
Posts: 11
Joined: 09. February 2010 18:52

Re: php won't exec perl module

Postby JonB » 30. June 2010 15:04

I kinda edited my last post, to give you a chance to do some diagnostics.

The 'missing' part of my post is this. I suspect that on Windows, scripts are not considered executables. If you look at some of those examples, you'll see that the Windows systems have a hard time invoking batch files (they are a script also). I have a pretty good concept that for the Windows OS, an executable is defined as an .exe or .com file (and for our purposes that means .exe). In fact, that appears to be what your tests show - executables work, scripts don't. Imagick (on windows) is a DLL (dynamic link library), which is an extension of a running executable -- so its a bit different, the executable has already been invoked.

So I think what may be needed is the backticks/shell_exec method. This can return the output of an external command to the PHP process. I think the code you have written actually tries to run the script external to the PHP process (if it were to run successfully), The STDOUT is most likely suppressed, in fact I think you might have to write it (the output of the Perl script) to a file to get the invoked script to run. If you do some research, I think you will find that PHP requires an external command to complete in the background (i.e) STDOUT is not available (only one process can have control of a stream like STDOUT/STDIN/STDERR at a time).

These are all suppositions, as I don't 100% know what you were trying to achieve. IF it was to direct the output of the Perl script back into the PHP process (for instance to display/print it), I don't think the 'exec' method will work. This is an expert level PHP question, and I'd give a whack at some PHP forums for a better answer.

I'm still going to look in my other book of tricks, I think there's another way to do this with Java/XML.

Good Luck.
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: php won't exec perl module

Postby ebohatch » 30. June 2010 23:14

JonB,
Thanks for all your help. Something is screwy, maybe it is Windows 7. unfortunately all of my desktops and
my laptop have Win 7. The following call exec("perl -v"); is not trying to run a script all it should do is display the Version info,
which works fine when I put in a command line.

I had been struggling for 2 days wondering why an old package I made, a photo album in PHP
with a call to a Perl module to do the image manipulations.
It worked fine on my system and on the website I had, this was back in 2007.
I was about to re-install it so I decided to test it out on my system.
I installed xampp and loaded Joomla and Wrodpress and my other websites.
All was fine until I tried to implement my photo album, got, PHP errors with deprecated functions and cleaned them up.
Therefor I assumed that the Perl module was out of date too.

I will put xampp on my other systems and see if I get the same results. Don't have an XP system.

After that I will completely remove xampp and do a fresh install of the latest Apache, Mysql, PHP and Perl.

I will report back here with my findings.

Again Thanks,
Emil
ebohatch
 
Posts: 11
Joined: 09. February 2010 18:52

Re: php won't exec perl module

Postby ebohatch » 03. July 2010 17:22

This doesn't make sense but it works.

I un-installed xampp from one of my desktops, then did a clean install of the latest Apache, Php, Mysql, & Perl

everything installed fine, when I tried to run exec("perl -v"); I still would get nothing.

I have 2 systems setup as dual boot with Ubuntu 10 so I booted up 1 of them and installed all of the packages (Apache, etc.)
to get a functioning webserver. BUT again when I tried the exec("perl -v"); from a php script it does nothing, just like my Win 7 systems.

I searched for more problems like this, found nothing. Finally I decided to use the system command it appears to do the same as an exec command (execute an external command). Worked like a champ. All of my old code worked fine once I changed any exec calls to system calls.

Did this on both systems where I had xampp installed and where I installed the Apache, PHP Mysql, Perl separately. And it also worked on the Ubuntu Apache system.
ebohatch
 
Posts: 11
Joined: 09. February 2010 18:52

Re: php won't exec perl module

Postby JonB » 03. July 2010 17:49

Well I guess that is settled, LOL.

I think that method may have worked on the old system because someone (likely a system engineer) had rigged things to work that way (with the 'exec' call). That use may have been deprecated since.

Thanks for the testing and info.

8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 65 guests