Connecting Tech Pros Worldwide Forums | Help | Site Map

Best way to run a perl script from php on windows?

Justin
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi. I have a perl script that can be run at the command line to take some
HTML and do something filtering with it.

What I want to do is use it from within PHP (run the script on a var, eg:
echo fancyHtmlFilter($inputHtml); ).

I've thought about accessing the perl script via HTTP, but then I would have
to modify the perl script to accept data from HTTP forms, which I have no
idea how to do.

I've played around quite a bit with PHP prog exec functions, but having
problems getting an output, or getting it to run the script full-stop most
of the time, and have no idea how I'm supposed to pass the HTML/data to it.

I'm running windows BTW, so that's probably half the problem.

Does anyone know what the best way to approach this is? Any good tutorials
specificly for passing/outputting data from command-line run perl scripts?
Can't seem to find anything.


Thanks, Justin.



Jeffrey Silverman
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Best way to run a perl script from php on windows?


On Tue, 23 Mar 2004 19:57:06 +1200, Justin wrote:
[color=blue]
> Does anyone know what the best way to approach this is? Any good tutorials
> specificly for passing/outputting data from command-line run perl scripts?
> Can't seem to find anything.[/color]

How much searching did you do?

Anyways, here are some pointers:
http://us2.php.net/passthru
http://us2.php.net/manual/en/function.system.php
http://us2.php.net/manual/en/function.exec.php
http://us2.php.net/manual/en/languag....execution.php
http://us2.php.net/manual/en/functio...peshellarg.php
http://us2.php.net/manual/en/functio...peshellcmd.php
http://us2.php.net/manual/en/features.safe-mode.php

later...
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/

Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Best way to run a perl script from php on windows?



Uzytkownik "Justin" <usernet@soupisgoodfood.network> napisal w wiadomosci
news:GVR7c.3011$u%1.431646@news02.tsnz.net...[color=blue]
> I've played around quite a bit with PHP prog exec functions, but having
> problems getting an output, or getting it to run the script full-stop most
> of the time, and have no idea how I'm supposed to pass the HTML/data to[/color]
it.[color=blue]
>
> I'm running windows BTW, so that's probably half the problem.
>
> Does anyone know what the best way to approach this is? Any good tutorials
> specificly for passing/outputting data from command-line run perl scripts?
> Can't seem to find anything.[/color]

Presumably the PERL script grabs the HTML from stdin. It'd be pretty hard
for PHP to communicate directly with the PERL process, as the PHP API
haven't include low level interprocess functions. With a bi-directional pipe
you run the risk of the two deadlocking. The more reliable--though not very
elegant--solution is to write the HTML into a temp file, pipe it into the
PERL script, and capture the output:

$tempfile = tempnam();
file_puts_contents($tempfile, $html);
$output = `perl < "$tempfile"`;


Closed Thread