通常,您可以通过使用通用语言格式并使用
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)


