dqqs64238
2016-05-03 13:15
浏览 230
已采纳

如何在PHP中运行时打印Python输出

I want to display the output of the python script at runtime on the web browser through php. Can someone help upon this..??

I'm calling a simple python script through php here is the code: run.py:

  import os
    import subprocess
    import sys
    import time
    print "<br> Hi from Python"
    sys.stdout.flush()
    for i in range(0,5):
        time.sleep(1)
        print "<br> Hi from Python"
        sys.stdout.flush()

this is the php script:

<?php
$handle = popen("python run.py ", 'r');
while(!feof($handle)) {
$buffer = fgets($handle);
echo "$buffer<br/>
";
ob_flush();
}
pclose($handle);
?>

Can someone help upon this..??

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题