dongmei6426 2015-06-23 14:01
浏览 19

php无法从一个上层目录执行我的python脚本

python

import os
import sys

if len(sys.argv) > 1:
  output = ""
  for i in range(1, len(sys.argv)):
    output = output + sys.argv[i] + ' '
else:
  output = "no argument found"

print "Hello World!!!"
print output

php

<?php
$data = "Testing";
exec("python SA/test.py $data", $output, $ret);
foreach($output as $result)
    echo $result."<br/>";
echo $ret;
?>

My python script file is located in SA folder which is same directory with my current php file. My python script work fine in terminal but when I execute it through php, $result show empty and $ret show 2 on screen. Anyone know why it happened in this way? Any solutions?

Addition: The python script also work fine if it is located in same folder with the that php file.

  • 写回答

1条回答 默认 最新

  • doudansui6650 2015-06-23 15:18
    关注

    I just found out a solution to solve it. Just change the permission of the folder with the command chmod 777, then everything work fine now.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)