[sf-perl] Perl DBI => named pipe => sqlldr => Oracle table
Loo, Peter # PHX
Peter.Loo at source.wolterskluwer.com
Tue Jun 13 10:36:32 PDT 2006
Hello All,
I have the need to spawn two processes within Perl and was wondering if
someone can show me the way.
One process open() a named pipe and the other runs "sqlldr
user/pass at database <BLOCKED::mailto:user/pass at database>
control=controlfile.ctl etc...". The problem I am having is, when I
attempt to "open(NP, "> $namedPipe")" before executing sqlldr, the
program hangs at "open()" so I can't continue with the program to
execute sqlldr process. If I start sqlldr first, then open(), sqlldr
does not read in the data from the open().
Here is my test program:
$pipeFile = "/tmp/$d_tblName";
unless (-p $pipeFile) {
print "$pipeFile does not exist.\n";
unless (mkfifo($pipeFile, 0777)) {
print "Can't mknod $pipeFile: $!\n";
exit;
}
}
########################################################################
#####
# COMMENTS: Connect to the source database and prepare the SQL statement
to #
# start fetching the data to send to the named pipe.
#
########################################################################
#####
$s_dbh = sub_connect($s_dbDriver, $INSTANCE, $DBUSER, $DBPASS);
$s_dbh->{RowCacheSize} = 500;
($stmtType, $s_sqlString) = sub_readSQLFile(qq{$SQLDIR/$SQL});
$s_sth = sub_prepare($s_dbDriver, $s_dbh, qq{$s_sqlString});
$s_sth = sub_execute($s_dbDriver, $s_dbh, $s_sth);
$cnt = 0;
########################################################################
#######
# COMMENTS: Open the named pipe file and start writing to it with the
fetched #
# data from the source database.
#
########################################################################
#######
print STDERR "Opening $pipeFile file to begin writing data.\n";
open (FIFO, "> $pipeFile") or die "$!\n"; <=================
It hangs right here.
print STDERR "Entering while loop to fetch the source data.\n";
while ($row = $s_sth->fetchrow_arrayref()) {
die "Pipe file disappeared.\n" unless -p $pipeFile;
#printf(STDERR "%s\n", join($delim, @$row)) if ($DEBUG);
printf(FIFO "%s\n", join($delim, @$row));
$cnt++;
}
print STDERR "We are done with while loop. Closing named pipe.\n";
close(FIFO);
print "Removing named pipe: $pipeFile\n";
print "Unable to delete $pipeFile.\n" unless (unlink($pipeFile));
So my question is, is there a way to force Perl to continue after the
open() statement so that I can execute "sqlldr" statement to start
receiving data from the named pipe?
Thanks in advance.
Sincerely,
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20060613/658469df/attachment.html
More information about the SanFrancisco-pm
mailing list