我尝试将值从 php 传递给 py 但我没有显示任何内容

我正在处理这个项目,我尝试将变量从 php 传递到 python 以执行 python 代码,但它没有显示任何内容。然后我在互联网上查找一些来源并完全复制相同但它没有显示任何内容


我的 test.php


<?php

  $data = 'hello';

  $output = shell_exec("python3 /Applications/XAMPP/xamppfiles/htdocs/project/test.py "  . $data);

 ?>

我的测试.py


import sys

result = sys.argv[1]


print (result)


慕少森
浏览 88回答 1
1回答

守候你守候我

你用 shell_exec 给 python 3 个参数。第一个始终是 python3,在您的情况下,第二个是/Applications/XAMPP/xamppfiles/htdocs/project/test.py,第三个是'hello'. 参数列表 ( sys.argv) 如下(顶部的数字是列表索引):&nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2['python3', '/Applications/XAMPP/xamppfiles/htdocs/project/test.py', 'hello']如果要存储变量“hello”,则需要选择列表中的其他索引:result = sys.argv[2]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python