Ronald is much more knowledgable than I am, but I _do_ think your
problem is related to opening STDOUT.  Try an earlier suggestion of
opening and writing to a different filehandle other than STDOUT, and see
if your script still hangs - if that works fine than you know your
problem is related to opening STDOUT.

Just to beat the dead horse into total submission, here's one final
article on using OPEN to redirect STDOUT to a file:

    http://www.rocketaware.com/perl/perlfunc/open.htm

Here's a snippet from that fairly short article:

=====================================

Here is a script that saves, redirects, and restores STDOUT and STDERR:


    #!/usr/bin/perl
    open(SAVEOUT, ">&STDOUT");
    open(SAVEERR, ">&STDERR");


    open(STDOUT, ">foo.out") || die "Can't redirect stdout";
    open(STDERR, ">&STDOUT") || die "Can't dup stdout";


    select(STDERR); $| = 1;     # make unbuffered
    select(STDOUT); $| = 1;     # make unbuffered


    print STDOUT "stdout 1\n";  # this works for
    print STDERR "stderr 1\n";  # subprocesses too


    close(STDOUT);
    close(STDERR);


    open(STDOUT, ">&SAVEOUT");
    open(STDERR, ">&SAVEERR");


    print STDOUT "stdout 2\n";
    print STDERR "stderr 2\n";

=====================================

HTH.

Hardy Merrill

>>> Laurie Vien <[EMAIL PROTECTED]> 03/24/04 03:18PM >>>
There are only 3 records in the input table, and they've all been
processed
to the output file.  :-)

-----Original Message-----
From: Ronald J Kimball [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 24, 2004 3:22 PM
To: 'Hardy Merrill'; [EMAIL PROTECTED]; [EMAIL PROTECTED] 
Subject: RE: Why won't my script terminate?


She's not re-opening STDOUT as an "in memory" file, she's opening it as
a
regular file handle.  This doesn't apply.

I doubt very much that opening STDOUT to a file is the cause of the
script
not terminating.  I suspect that either there is an infinite loop, or
there's just a lot of data to process and the original poster isn't
allowing
enough time for the script to finish.

Ronald


> -----Original Message-----
> From: Hardy Merrill [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, March 24, 2004 3:06 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED] 
> Subject: Re: Why won't my script terminate?
> 
> I just found this in 'perldoc -f open':
> 
>     Though if you try to re-open "STDOUT" or "STDERR" as an "in
>     memory" file, you have to close it first:
> 
>         close STDOUT;
>         open STDOUT, '>', \$variable or die "Can't open STDOUT: $!";
> 
> So try closing STDOUT first before opening it for append.
> 
> HTH.
> 
> Hardy Merrill
> 
> >>> Laurie Vien <[EMAIL PROTECTED]> 03/24/04 02:44PM >>>
> I am running a very simple Perl script using DBI (skeleton of it
> follows).
> It does everything I expect it to, but the problem is it doesn't
> finish
> until I Ctrl-C, at which time I get the message "Terminating on
signal
> SIGINT(2)".  What have I left out or done in the wrong order that
> causes it
> not to terminate?:
> 
> #MyPerlScript.pl
> use DBI;
> use Date::Manip;
> 
> $dbh = DBI->connect($DB_CONN, $DB_USER, $DB_PASS) || die "Can't
> connect:
> $dbi::errstr";
> open(STDOUT, ">>myfile.txt") or die "\nCould not open STDOUT: $!";
> 
> $sth = $dbh->prepare("SELECT * FROM MyTable");
> $sth->execute();
> 
> # < Do bunches of stuff here ....>
> #
> #
> 
> $sth->finish();
> $dbh->disconnect();
> close(STDOUT);
> 
> Laurie
> 

Reply via email to