如何在php脚本中的php变量中获取python脚本中的打印值? [英] How can i get the print values in python script in php variables in php script?

查看:82
本文介绍了如何在php脚本中的php变量中获取python脚本中的打印值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本,可以对图像进行一些处理并提供文本,该脚本在控制台中运行良好.现在,我想在浏览器中使用php显示相同的文本.

I have a python script which do some processing over images and gives me text, the script is running fine in the console. Now i want to display the same text by using php in a browser.

当我使用以下代码时,当我从控制台中执行代码时,我在php变量$ f和$ v中获得了正确的值,但是当我从浏览器中执行代码时,我在php变量中却没有任何值

When i use the below code, i get the proper values in php variables $f and $v when i exectute the code from console but when i execute the code from browser i don't get any value in php variables

   exec('python /var/www/abc/abc.py', $f, $v);
   echo $f;
   echo $retval;

在python脚本中:我有类似的东西

In python script: I have something like this

  code...
  code...
  ......
  #in the end
  print text
  sys.stdout.flush() 

如何在php变量中获取python脚本中的打印值?

How can i get the print values in python script in my php variables??

推荐答案

在调用exec()之前,确保$f是一个数组,然后print_r($f)应该可以解决问题

Make sure $f is an array before calling exec(), then print_r($f) should do the trick

这篇关于如何在php脚本中的php变量中获取python脚本中的打印值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆