设置环境变量时通过php运行python不起作用?

时间:2014-05-21 18:32:01

标签: php python exec environment-variables ld

我正在尝试通过php运行python脚本

python脚本

#!/export/home/oracle/python64/bin/python

import os
os.environ['LD_LIBRARY_PATH']='/export/apps/oracle/products/11.1.0.7.1/lib:/export/apps/oracle/products/11.1.0.7.1/lib32:/export/home/oracle/gli/gnu/gcc/lib:/export/home/oracle/gnu/curl/lib:/export/home/oracle/gnu/gcc/lib/sparcv9';
import cx_Oracle

def do_this():
        conn = cx_Oracle.connect(mode = cx_Oracle.SYSDBA)
        curs = conn.cursor()
        showparam_sql = 'select name from v$database'
        curs = curs.execute(showparam_sql)
        with open("data.txt", "w") as f:
                for col1 in curs.fetchall():
                        f.write("SID IS" + str(col1))

        curs.close()
        conn.close()


do_this();

PHP脚本

<?php


if(isset($_POST['submit']))
{
$py="./exec_py.py";

exec("$py 2>&1", $output);
print_r($output);
}
?>

所以,我仍然得到错误

Array ( [0] => Traceback (most recent call last): [1] => File "./exec_py.py", line 5, in [2] => import cx_Oracle [3] => ImportError: ld.so.1: python2.7: fatal: /export/apps/oracle/products/11.1.0.7.1/lib32/libclntsh.so.11.1: wrong ELF class: ELFCLASS32 ) 

即使我修改了LD_LIBRARY_PATH ENV VARIABLE。

另外, 当我直接通过终端运行python时,我不会收到任何错误。 为什么?我最近使用新的LD_LIBRARY_PATH修改了cshrc_custom我是否需要重启我的php服务器才能读取新的env?

0 个答案:

没有答案