0

I have python file which is newtry.py and this is my code:

print ("hello world")

I also have php file which is importKeyword.php and this is my code:

<?php
$python = `python newtry.py`;
echo $python;
echo "yes";
 ?>

I want to print "hello world" from python in the browser but it only print "yes" which is from php file. I have look at this solution which is using backquote operator ( enter link description here ) and wondering why I can't make it.

Dolly Aswin
  • 2,456
  • 1
  • 17
  • 19

2 Answers2

0

You can use exec function

exec('python newtry.py', $output);
var_dump($output);
Ivan Bolnikh
  • 742
  • 8
  • 19
0

use 2>&1 to redirect the output

<?php
exec("python newtry.py 2>&1", $python);
print_r($python);
echo "yes";
?>
uingtea
  • 4,918
  • 2
  • 19
  • 34