2

I am trying to run a python script through php

python script

#!/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 script

<?php


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

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

SO, I still get the error

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 ) 

even though I modified the LD_LIBRARY_PATH ENV VARIABLE.

Also, When I run python directly through the terminal i don`t get any error. WHy? I recently modified cshrc_custom with the new LD_LIBRARY_PATH do I need to restart my php server for it to read the new env?

  • See http://stackoverflow.com/questions/6543847/setting-ld-library-path-from-inside-python - you need to set `LD_LIBRARY_PATH` before starting the Python process. Once you're inside the process, the dynamic linker has already cached whatever the initial value was and your modifications don't have any effect. Having set `LD_LIBRARY_PATH` in your `cshrc` explains why it was working in the terminal. – nobody May 21 '14 at 21:34

0 Answers0