Cannot run bash script in PHP

I am trying to run a bash script in PHP, but cannot run it. php -v

PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

Ubuntu 12.04 LTS 64 bit.

My php code is:

    $cmd='/www/var/pl/bash.sh';
    $retval =-1;
    exec( $cmd, $output ); //executing the exec function.
    foreach( $output as $tmp ) 
    { 
        echo "$tmp <br>"; 
    };

bash.sh:

 #!/bin/bash
swipl --quiet -s /var/www/pl/ples.pl -g "f(R, gel), writeln(R),open('/var/www/pl/in.txt',write, Stream),
write(Stream, (R)),
nl(Stream),
close(Stream)" -t halt.

What am I doing wrong?

And I can run bash.sh in a Linux terminal.

+5
source share
2 answers

When you run the script in the terminal, you execute it under the account you are logged into. You have shell customization using search path, etc.

When php executes the script, it does not have a shell installation and runs under the web server user account. While doing:

  • make sure you have the full path to the file, swiplnot enough, it should be/path/to/swipl
  • , - , , .
+5

, ; , , -, , swipl.

2 > & 1 exec ', , . stderr - ( PHP, php.ini).

0

All Articles