简体   繁体   中英

Php exec script of python return empty string

I am executing a python script from a php one by an exec command receiving an empty result. If I execute the python command from the shell, it correctly returns the right results, and the logs are silent; this is my php function:

public function poll($palina){
    //set_include_path("/var/www/html/iPhone/inarrivo/python");
    $pythonCommand="python3.4 ../../python/palina.py $palina";
    $result=exec($pythonCommand);
    echo "<blank>command=$pythonCommand result=$result</blank>";
    $resultData = json_decode($result, true);
    if (!is_array($resultData)) {
        error_log($resultData);
        $resultData=Array();
    }
    //print_r($resultData);
    return $resultData;
}

and this is the called python script:

#!/usr/local/bin/python3.4

# change above line to point to local 
# python executable

from xmlrpc.client import Server
from pprint import pprint
import sys, json
import datetime, time
palina=sys.argv[1]
DEV_KEY = 'UuC378Q3l3Y4vtF8q2Hj3i5Up6OmZKb2'

s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')
token = s1.autenticazione.Accedi(DEV_KEY, '')
res = s2.paline.Previsioni(token, palina, 'it')
#pprint(res)
arrivi=res.get('risposta').get('primi_per_palina')[0].get('arrivi')
myList=[]
for arrivo in arrivi:
    if 'nessun_autobus' not in arrivo and 'non_monitorata' not in arrivo:
        output={}
        acapolinea=arrivo.get('a_capolinea')
        output["busDestination"]=arrivo.get('destinazione')
        output["wait"]=arrivo.get('annuncio')
        if output["wait"]=='In Arrivo':
            output["receiving"]=1
        else:
            output["receiving"]=0
        meb=arrivo.get('meb')
        output["busNumber"]=arrivo.get('linea')
        output["busLines"]=arrivo.get('id_percorso')
        output["time"]=arrivo.get('tempo_attesa')
        output["stops"]=int(arrivo.get('distanza_fermate'))
        output["palina"]=arrivo.get('id_palina')
        output["inarrivo"]=arrivo.get('in_arrivo')
        partenza= arrivo.get('prossima_partenza')
        if acapolinea == 1:
            output["receiving"]=2
            output["acapolinea"]=acapolinea
            if partenza:
                s = datetime.datetime.strptime(partenza.value, "%Y%m%dT%H:%M:%S")
                output["capolineaDate"]=s.strftime('%H:%M')
        myList.append(output)
print (json.dumps(myList));

This script worked fine on a previous server. Is there some configuration to be set on Centos to have php and python correctly integrated?

python脚本需要具有完整路径才能起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM