Re: something is killing my perl script

2004-06-04 Thread Peter Scott
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Parker Richard-A19798) writes:
>I have a program that I wrote which take input from a pipe and then distributes 
>to certain log files.
>
>What happens is that for no particular reason that I can find, the program dies.
>
>What do I put in to find out what killed it or what it died from?

Others are addressing the program itself, but a general answer to your
question is to insert

use Carp qw(confess);
$SIG{__DIE__} = sub { confess @_ };

near the top of your program.  You should then get more information when it
dies.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


Re: something is killing my perl script

2004-06-03 Thread Claude
> "Parker" == Parker Richard-A19798 <[EMAIL PROTECTED]> writes:
[...]

Parker> What happens is that for no particular reason that I can find,
Parker> the program dies.

Parker> What do I put in to find out what killed it or what it died from?

I have no idea, but I thought this code is more conventional:

  open KERNFIFO, "/dev/log.fifo" or die "Cannot open file, $!\n";

  while ( my $line =  ) {
  print "$line";
  }

Parker> #!/usr/bin/perl
Parker> open (KERNFIFO, "cat /dev/log.fifo |");
Parker> while (  ) {

[...]
-- 
Claude


Re: something is killing my perl script

2004-06-03 Thread Dave Barnett
Rick:

Well, as a first idea, when you run a command via backticks (`), I believe the 
$? variable gets set with the return value.  Most people don't check it.  
See perldoc -f system to see how to decode the return value.

Might I suggest a more Perl-centric way of doing this, as well as a few bits 
that you will find useful in all your scripts  Yes, "-w" or "use 
warnings;" and "use strict" can be a pain until you get used to them.  Once 
you're used to them, you begin seeing the things that strict will gripe about 
while you're writing the code.  Anyway, my Perl-centric method:

 #!/usr/bin/perl -w
#
# By turning on "-w" and "use strict", the Perl compiler will complain if it
# isn't happy about something
use strict; 

 open (KERNFIFO, "cat /dev/log.fifo |");

 while (  ) {
if ( /fbd_ioctl/ ){
#print "Skipping line... $_";
}
elsif ( /\bslot/ ) {
#   $cards = $_;
#   `echo "$cards" >> /var/log/cards/messages`;
open(CARDS, ">>/var/log/cards/messages') or die 
"open /var/log/cards/messages: $!\n";
print CARDS "$_\n";
close(CARDS) or die "close /var/log/cards/messages: $!\n";
}
else {
#   $line = $_;
#   `echo "$line" >> /var/log/messages`;
open(LOG, ">>/var/log/messages') or die "open /var/log/messages: $!\n";
print LOG "$_\n";
close(LOG) or die "close /var/log/messages: $!\n";
}
 }


Hope this helps.

Cheers,
Dave


On Wednesday 02 June 2004 12:25 pm, Parker Richard-A19798 wrote:
> I have a program that I wrote which take input from a pipe and then
> distributes to certain log files.
>
> What happens is that for no particular reason that I can find, the program
> dies.
>
> What do I put in to find out what killed it or what it died from?
>
> #!/usr/bin/perl
>
> open (KERNFIFO, "cat /dev/log.fifo |");
>
> while (  ) {
>   if ( /fbd_ioctl/ ){
>   #print "Skipping line... $_";
>   }
>   elsif ( /\bslot/ ) {
>   $cards = $_;
>   `echo "$cards" >> /var/log/cards/messages`;
>   }
>   else {
>   $line = $_;
>   `echo "$line" >> /var/log/messages`;
>   }
> }
>
>
>
>
>
> Rick Parker
> Motorola Inc. / Winphoria Division
> 3 Highwood Drive, WEST
> Tewksbury, MA 01876
> (978) 805-5686
> [EMAIL PROTECTED]
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.690 / Virus Database: 451 - Release Date: 5/22/2004