栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在PHP中执行Python脚本并在两者之间交换数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在PHP中执行Python脚本并在两者之间交换数据

通常,您可以通过使用通用语言格式并使用

stdin
stdout
来传递数据来在语言之间进行通信。

PHP / Python示例,使用shell参数通过JSON发送初始数据

PHP:

// This is the data you want to pass to Python$data = array('as', 'df', 'gh');// Execute the python script with the JSON data$result = shell_exec('python /path/to/myscript.py ' . escapeshellarg(json_enpre($data)));// Depre the result$resultData = json_depre($result, true);// This will contain: array('status' => 'Yes!')var_dump($resultData);

蟒蛇:

import sys, json# Load the data that PHP sent ustry:    data = json.loads(sys.argv[1])except:    print "ERROR"    sys.exit(1)# Generate some data to send to PHPresult = {'status': 'Yes!'}# Send it to stdout (to PHP)print json.dumps(result)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/466112.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号