CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
File Handle is not working in Perl while calling from Oracle

 



SourajitSeth
New User

Jul 30, 2010, 3:26 AM

Post #1 of 7 (2608 views)
File Handle is not working in Perl while calling from Oracle Can't Post

Hi,

I have written the perl script first times. The perl script is called by Unix shell script ( Say X) , and the Unix is called by Oracle. Earlier another unix shell ( Say Y) was called by X and currently we have the requirement to use Perl instead of Y. My perl Script is running fine while I executed it directly from X. But When I try to execute it by calling the Oracle, it is failed, though no error message is displayed. After debugging the perl script, I found that, when ever I use any command related to file ( Like File Exists, Open and Read file) , the script fails. If I remove the file related commands , it is working fine. The syntax in the code seems correct , since I am able to run the script while calling directly or from X. Earlier all the file related commands were successfully executed through Y. Please let me know, whether any configuration is required for Perl ( Or in Oracle) to handle the files ?

Thanks in Advance


FishMonger
Veteran / Moderator

Jul 30, 2010, 5:45 AM

Post #2 of 7 (2603 views)
Re: [SourajitSeth] File Handle is not working in Perl while calling from Oracle [In reply to] Can't Post

Since it is failing without any errors, I'd say that you're lacking proper error handling.

Can you post your code?


SourajitSeth
New User

Jul 30, 2010, 7:05 AM

Post #3 of 7 (2595 views)
Re: [FishMonger] File Handle is not working in Perl while calling from Oracle [In reply to] Can't Post

Thanks for your response. I do not have much idea about error handing process. If I run though Unix , I can get the message from "print" or "die" command. Not sure how should I manage it while calling from Oracle. I have a plan to log the error in a file. But not able to read/write any file. Attached is the code. Please verify that.


FishMonger
Veteran / Moderator

Jul 30, 2010, 7:11 AM

Post #4 of 7 (2588 views)
Re: [SourajitSeth] File Handle is not working in Perl while calling from Oracle [In reply to] Can't Post

You forgot to post your script as an attachment.


(This post was edited by FishMonger on Jul 30, 2010, 7:11 AM)


SourajitSeth
New User

Jul 30, 2010, 7:13 AM

Post #5 of 7 (2585 views)
Re: [FishMonger] File Handle is not working in Perl while calling from Oracle [In reply to] Can't Post

It is attached now.
Attachments: code_ftp.pl (1.03 KB)


FishMonger
Veteran / Moderator

Jul 30, 2010, 8:01 AM

Post #6 of 7 (2580 views)
Re: [SourajitSeth] File Handle is not working in Perl while calling from Oracle [In reply to] Can't Post

When using || in the open call, you need to use the parens like you did in the first open call.

What was the exact error message?

The open call most likely failed because when you run the script via Oracle, it is probably running with a different environment that when you run it directly.

Remove the -w switch then add these 2 pragmas and fix the problems that they point out.

Code
use warnings; 
use strict;


Use the 3 arg form of open and a lexical var for the filehandle instead of the bareword.

Code
open my $ftpfile, '<', $FTP_FILE or die "Can't open <$FTP_FILE>: $!";


Try this version and post the exact error message

Code
#!/usr/bin/perl 

use strict;
use warnings;
use Net::FTP;

die "wrong number of args if @ARGV != 3;

my $subdir = $ARGV[0];
my $batch_id = $ARGV[1];
my $rdbms_id = $ARGV[2];

my $scripttop = $ENV{'script_top'};
my $dir_path = $ENV{'dir_path'};

my $full_path = "$dir_path/$subdir";
my $log = "$full_path/log";
my $ftp_file = "$scripttop/1.log";
my $log_file = "$log/$batch_id.log";


open my $ftpfile, '<', $ftp_file or die "can't open <$ftp_file>: $!";

my @lines = <$ftpfile>;

close $ftpfile;

print @lines;



SourajitSeth
New User

Aug 2, 2010, 2:42 AM

Post #7 of 7 (2529 views)
Re: [FishMonger] File Handle is not working in Perl while calling from Oracle [In reply to] Can't Post

Thanks for your valuable advise. Unfortunately the code also is not working and do not generate any error message. Currently we are returning back to shell script due to timeline constraint. If you have any better idea and useful links for the beginners , please share with us. I will try to learn later.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives