LinuxUser2008 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am having a script, which connects to an Oracle DB.. This script when invoked via command line works fine, but when invoked via a browser throws an error.. I realised that this error is caused because of not setting the env variables..
After a bit of digging around I found that there is a way to solve it and I am able to remove the error and get the script working in the Browser now, but this is done using crle.. Using crle means that i am changing the Env Variables of the system in a global level, so i assume, this may interfere with certain other processes.. I need to find an alternative way for the script to get to work.. Could someone shed some light on this issue??
Regards,
Blub:)

Replies are listed 'Best First'.
Re: Env Variables
by almut (Canon) on Jun 10, 2010 at 15:30 UTC

    In case the environment variables in question involve LD_LIBRARY_PATH, and in case you're using Apache, see SetEnv/PassEnv.

    LD_LIBRARY_PATH is special in that (on some operating systems like Solaris1) it needs to be set before the process is started that would need it for dynamic linking (this is because the runtime linker caches the search paths on exec). That means that simply changing the environment from within the script itself may not work.

    In case you do want to set it from within the script (as opposed to having the webserver set it, as suggested above), you'll need to re-exec the script after having changed the environment. This has been discussed a few times here, so you should be able to find related sample code.  Update: see PATH is not setting - PERL, for example.

    ___

    1 as you mentioned crle, I figured you might be on Solaris

      U are like the Sherlock Holmes in Computer Land man .. Awesome... Anyway, Do you know of any other way by which Dynamic Linking Lib paths can be set, other than LD_LIB_PATH and crle??
      Cause among two Solaris boxes, the code executes fine even on the browser, without setting libs using crle..

      Regards,
      Blub:)

        Before trying other things I would try something like:

        #!/usr/bin/perl BEGIN { unless ($ENV{DONE_RESTARTING_MYSELF}) { # avoid endless loop... $ENV{DONE_RESTARTING_MYSELF} = 1; $ENV{ORACLE_HOME} = "/opt/oracle/product/10.2.0/client_1"; $ENV{LD_LIBRARY_PATH} = "/opt/oracle/product/10.2.0/client_1/l +ib32:/usr/local/lib/sprolib:/usr/local/lib:/usr/lib:/usr/openwin/lib: +/usr/dt/lib:/usr/lib:/usr/ucblib"; exec $0, @ARGV; # <--- } } use DBI; # ...

        Or simply use a shell wrapper around your Perl script:

        #!/bin/sh export ORACLE_HOME=/opt/oracle/product/10.2.0/client_1 export LD_LIBRARY_PATH=/opt/oracle/product/10.2.0/client_1/lib32:/usr/ +local/lib/sprolib:/usr/local/lib:/usr/lib:/usr/openwin/lib:/usr/dt/li +b:/usr/lib:/usr/ucblib /path/to/your/script.pl

        As for the ELFCLASS64 error, the reason is that the (64-bit) lib is being found in /opt/oracle/product/10.2.0/client_1/lib, instead of the 32-bit one in the .../lib32 directory that you tried to specify via LD_LIBRARY_PATH — because setting the env variable too late (after exec of perl) doesn't have any effect, as already mentioned.

Re: Env Variables
by marto (Cardinal) on Jun 10, 2010 at 15:12 UTC

    Something like $ENV{'ORACLE_HOME'} = $your_oracle_home;?

    Update: s/orace/oracle/

      Yes, I have set that.. But still no go..

        Can you post relevant code please?

Re: Env Variables
by moritz (Cardinal) on Jun 10, 2010 at 15:08 UTC
    Just modify %ENV.
    Perl 6 - links to (nearly) everything that is Perl 6.
      Thanks for the ultra quick response dude(ette)..
      I am aware of %ENV hash, I am setting $ENV{'LD_LIBRARY_PATH'}=ORACLE_LIB_DIRECTORY.. Even after setting this, i am getting an error.. But this error vanishes once i set the variable using crle..
        Is this the only environment variable you set? what's the error? Is there another process on the same machine involved?

        Also the DBD::Oracle documentation talks about connecting, environment variables and so on. Did you read it?