I'm beggining to develop the theory that things go awry when 
using exec from within a webserver-executed PHP script to call 
a shell script itself written in PHP. 

The example that I'm really trying to do might be too complicated for 
presentation here, but here's a simplified version.

Take the shell script "helloWorld.php":

        #!/usr/local/bin/php -q
        <?PHP print "\nHello World!"; ?>

Now take a calling wrapper:

        <?PHP

        $execStr = "/usr/home/jakus1/www/htdocs/form2mail/helloWorld.php";
        echo "\n<br>Calling: ($execStr)";

        $output = exec($execStr);

        echo "\n<br>Called: ($execStr)";
        echo "\n<br>output: ($output)";

        ?>

Note that there are no loops or recursing in those scripts. I bring that
up because of the bizzare results I'm getting. Brace yourselves:

        Calling: (/usr/home/jakus1/www/htdocs/form2mail/helloWorld.php) 
        Called: (/usr/home/jakus1/www/htdocs/form2mail/helloWorld.php) 
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: (
        output: ()))))))))))))))))))))))

        (See http://fsboutah.net/form2mail/testphpcall.php )

So... not only am I not getting the expected result back in $output, 
something really weird is going on.

If, however, I change the $execStr assigning line in the calling script to:

        $execStr = "ls -l";

I get what I expect:

        Calling: (ls -l) 
        Called: (ls -l) 
        output: (-rw-r--r-- 1 jakus1 vuser 193 Sep 23 01:27 testgrcall.php)

        (See http://fsboutah.net/form2mail/testlscall.php )

I wondered if it might just be a problem with calling bang-begun scripts, so
I tried a helloWorld.sh:

        #!/bin/sh
        echo Hello World

        (See http://fsboutah.net/form2mail/testshcall.php )

And got:

        Calling: (/usr/home/jakus1/www/htdocs/form2mail/helloWorld.sh) 
        Called: (/usr/home/jakus1/www/htdocs/form2mail/helloWorld.sh) 
        output: (Hello World)

        (See http://fsboutah.net/form2mail/testshcall.php )

Similar results for perl (see http://fsboutah.net/form2mail/testplcall.php ).


Anyone have an idea of the black magic that forbids trying to do this with php?


Thanks,
        Weston

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to