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,684
  • 1
  • 20
  • 23

2 Answers2

0

You can use exec function

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

use 2>&1 to redirect the output

<?php
exec("python newtry.py 2>&1", $python);
print_r($python);
echo "yes";
?>
uingtea
  • 6,002
  • 2
  • 26
  • 40