1
我使用「EXEC」調用函數和定義參數作爲一個變量。如何調用Python函數在PHP傳遞變量參數
$jsonrequest = escapeshellarg(json_encode($request, JSON_NUMERIC_CHECK));
$solveroutput = exec('sudo python /var/www/website.com/services/run.py $jsonrequest');
我已經嘗試過這樣的呼籲:
$solveroutput = exec("sudo python /var/www/website.com/services/run.py '$jsonrequest'");
和
$solveroutput = exec("sudo python /var/www/website.com/services/run.py $jsonrequest");
,也沒有 '須藤'
當我直接調用該函數在命令行在服務器(AWS),收到的結果,如下。上述$jsonrequest
正是我打字在命令行的方式。
[[email protected] ~]$ sudo python /var/www/website.com/services/run.py '{"max_split":4,"order":681,"max_cost_frac":0.1,"items":[{"productid":8745,"qty":1,"estimatedprice":53.6}],"bids":[{"vendorid":1,"minimum_order":0,"items":[{"productid":8745,"qty":1,"estimatedprice":100}]}]}'
迴應:
{"status": "OK", "order": 681, "deliveries": [{"vendorid": 1, "productid": 8745}]}
謝謝!