0

I'm running simple code in PHP to execute Python code, i write in 2 file: python n php.

PHP code : (exec.php)

<?php 

$command = escapeshellcmd("/opt/lampp/htdocs/latihan/php_python/pi.py");
$output = exec($command, $out, $status);
print_r($output);
#print_r($out[0]);
echo "</br>";
print_r($status);
echo "</br>";
echo "</br>";

$command = shell_exec($command);
echo "<pre>".$command."</pre>";
echo "\n";

ob_start();
passthru('python /opt/lampp/htdocs/latihan/php_python/pi.py');
$output = ob_get_clean(); 

if( ini_get('safe_mode') ){
   echo "safe mode is on";
}
else{
   echo "it's not";
}
?>

Python Code : (pi.py)

#!/usr/bin/env python
print("Hello !");

Result 1 : (execute in terminal ):

Hello !</br>0</br></br><pre>Hello !
</pre>
it's not

Result 2 : (execute in browser ):

127

it's not

My reference :

My file permission :

-rw-r--r-- 1 www-data www-data 488 Nov 26 11:13 exec.php
-rwxr-xr-x 1 www-data www-data  41 Nov 26 10:18 pi.py

My question is, why i can't show result from python in browser ?

It get status 0, is it cause ? i Change permission to www-data root for pi.py still got same result(and change other option for both www-data and root or just one of them).

i try run "ls -l" it success shown in browser tough,,

Budi Mulyo
  • 384
  • 5
  • 22

0 Answers0