Re: PATH is not setting - PERL
by halley (Prior) on Oct 15, 2007 at 12:54 UTC
|
Silly question, but are you running this Perl script and then running your application? Or are you running this Perl script which then executes your application?
Any changes you make to the environment in one process is only active for that process and its own subsequently forked/executed processes. It will NOT affect the shell that invoked your script.
Update: Sinistral, yours is one valid interpretation, and I doubt you can be sure from the Oracle tools he mentions that he's using it correctly. This is an area which has a lot of possible and common mistakes. As far as when to set LD_LIBRARY_PATH, this too should be possible on most platforms within the Perl script's process, as long as it's done early enough. For example, a BEGIN{} may be required before a certain use statement. Of course, there may be other hangups with a given httpd and perlmod that I won't explore today.
-- [ e d @ h a l l e y . c c ]
| [reply] [d/l] [select] |
|
The original poster is saying that the Perl code is his application. He's using the Oracle Instant Client as the source for the libraries needed by DBD::Oracle.
The answer to the problem is that you have to set then LD_LIBRARY_PATH before invoking the Perl script. You can do this by using a shell script to call your Perl script, by setting environment variables manually, or, if the Perl script is a CGI script invoked by Apache, using the SetEnv directive in the httpd.conf.
| [reply] |
Re: PATH is not setting - PERL
by cdarke (Prior) on Oct 15, 2007 at 12:28 UTC
|
Some packages (not sure about Oracle) don't like the trailing '/', that might be the problem. Alternatively, take a look at Env::C. | [reply] |
Re: PATH is not setting - PERL (LD_LIBRARY_PATH)
by tye (Sage) on Oct 15, 2007 at 18:24 UTC
|
Setting LD_LIBRARY_PATH after the perl executable is already running likely doesn't do any good on many systems. The "dynamic linker/loader" component has already read and cached a copy of the LD_LIBRARY_PATH value and so doesn't notice your change. A search for LD_LIBRARY_PATH will turn up many discussions of this point and possible work-arounds, such as those included in the DBI, DBD::Oracle and LD_LIBRARY_PATH thread.
| [reply] |
|
I added the same lines but I am getting the below error
"env:this is not a file or a directory"
BEGIN {
unless ($ENV{BEGIN_BLOCK}) {
$ENV{ORACLE_HOME} = '/opt/instantclient_10_2/';
$ENV{LD_LIBRARY_PATH} = '/opt/instantclient_10_2/';
#$ENV{TNS_ADMIN} = '/common/oracle/env';
$ENV{BEGIN_BLOCK} = 1;
exec 'env',$0,@ARGV;
}
}
Thanks
Sri | [reply] [d/l] |
|
You can replace 'env' with $^X and hope your dynamic loader doesn't notice that the perl executable is exec'ing the perl executable, like happens on some systems.
There are also lots of less 'tricky' ways that don't have this problem. For example, have a shell script (or ".bat" file) wrapper that calls your Perl script.
"env:this is not a file or a directory"
Oh, I just realized that this is probably not a copy'n'paste of the actual error message but more likely a bad hand copy job and the real error is closer to:
env: yourscript: No such file or directory
which means that exec 'env', $^X, $0, @ARGV; will likely work.
| [reply] [d/l] [select] |
|
|
|
|
Re: PATH is not setting - PERL
by perlfan (Parson) on Oct 15, 2007 at 14:52 UTC
|
Since you don't show the code in any sort of context, you're making us guess. So here's mine. Put in use strict; and use warnings;. I have a feeling that you're not modifying the %ENV that you think you are - i.e., it is not in the proper scope and you may be modifying the hash in a disjoint scope.
If you want real help, you'll have to show the code with enough context to show what is going on. | [reply] [d/l] [select] |
|
| [reply] [d/l] [select] |
|
What other %ENV is there in Perl?
You could make a lexical named %ENV, and it would mask %main::ENV. That doesn't appear to be the case here, but that's another one.
| [reply] [d/l] [select] |
|
below is my code
#!/usr/bin/perl
use DBI;
$ENV{'LD_LIBRARY_PATH'}= "/opt/instantclient_10_2/";
$ENV{'ORACLE_HOME'}= "/opt/instantclient_10_2/";
$database = "idm";
$username = "idm";
$password = "idm";
$hostname = "host";
$output = &connectCBMS(900010);
print $output;
sub connectCBMS {
print "Connecting to Database for user $staffcode";
$db = DBI->connect("DBI:Oracle:host=$hostname;sid=$database",$username,$password);
unless($db) {
print "(ERROR) Failed to connect to $hostname.";
return;
}
my ($staffcode) = @_;
# Execute a Query
my $sql = qq{ SELECT REGISTRATIONDAY FROM CBMS WHERE STAFFCODE = ? };
my $sth = $db->prepare( $sql );
print $staffcode;
$sth->bind_param( 1, $staffcode );
$sth->execute();
while ( $row = $sth->fetchrow_array()) {
if (!$row) {
return;
}
else {
return ($row);
}
}
$sth->finish();
$db->disconnect();
return;
}
Thanks
Sri | [reply] |
Re: PATH is not setting - PERL
by Anonymous Monk on Oct 15, 2007 at 11:29 UTC
|
| [reply] |
|
Begin{
$ENV{'LD_LIBRARY_PATH'}= "/opt/instantclient_10_2/";
$ENV{'ORACLE_HOME'}= "/opt/instantclient_10_2/";
};
And show more core of your scripts.
| [reply] [d/l] |
|
HI,
I am calling DB connection in my code. So the PERL program trying to find the LD_LIBRARY_PATH and ORACLE_HOME..
Though I set using $ENV , the perl program is not able to find both Environment variables and giving error.
If I manually set using export command , then works.
Thanks
Sri
| [reply] |