php调用python
test_python.php
<?php $k = $_REQUEST['k']; if (!empty($k)) { $k = trim($k); //$a 用来捕获输出 // 这里的arry 他是按照每一行'\r\n'当作一个元素 //$a = array(); // exec('python ./some.py '.$k, $a); //echo $a[0]; //if ($a[0].indexof("test")!=-1){echo "ok";} //python里的print的原样输出 passthru('python ./some.py '.$k); } ?>
some.py
#!/usr/bin/env python #-*- coding:utf-8 -*- import sys def do_some(a): return "dosome:%s" % a if __name__ == '__main__': #test write out fw=open("ajax_tmp.csv","w+") fw.write("name,value\n1,7178\n2,7906") fw.close print "ajax_tmp.csv" #test print a = sys.argv[1] if a: for i in range(0,10): T = do_some(a) print T