For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > Re: Running a program and killing it when encountering certain output









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Running a program and killing it when encountering certain output
jrpfinch

2006-10-13, 3:57 am

Wow something spectacular happens when I run this code:

while (!$SNMPReady) {
pauseWithProgressBar(60);
$pid=open (GETOID,"getnext -v2c localhost public
1.2.826.0.1.1578918.6.508.1.5 |") or die "Error opening GETOID: $!";
while (<GETOID> ) {
print 'Entering <GETOID> loop with $pid='."$pid".'...'."\n";
if ($_ eq "getnext: retrying . . .\n") {
print 'Killing $pid='."$pid\n";
kill 2, $pid;
#print "Process killed\n";
} else {
print ' $_='."$_\n";
}
}
close GETOID;
}

I get the screenoutput

$_=sysDescr.0 = SunOS release:5.8 version:Generic_108528-09
machine:sun4u

getnext: retrying . . .
at line 167 in file getnext.c
getnext: retrying . . .
at line 167 in file getnext.c
getnext: retrying . . .
at line 167 in file getnext.c
Entering <GETOID> loop with $pid=25132...
$_=Error code set in packet - General error: 1.

getnext: retrying . . .
at line 167 in file getnext.c
getnext: retrying . . .
at line 167 in file getnext.c
getnext: retrying . . .
at line 167 in file getnext.c
Entering <GETOID> loop with $pid=25254...
$_=Error code set in packet - General error: 1.

getnext: retrying . . .
at line 167 in file getnext.c

I have got round this by just entering the following and this seems to
solve the problem:

if ($_ =~ /^emsR1VersionLvl.*$/) {
print "SNMP ready\n";
$SNMPReady=TRUE;
} else {
kill 2, $pid;
}

However, if you have any ideas about why all the funny output appears,
I would be very grateful to know. With the new code I still get the
error messages so it would be great to know if there is a way to
suppress screen output.

Many thanks

Jon

Paul Lalli wrote:

> jrpfinch wrote:
>
> You either aren't using warnings, are ignoring warnings, or are never
> getting to this line. Which is it?
>
>
> Are you sure you're not properly killing the script, and then because
> you never set $SNMPReady to a true value, the loop is reexecuting and
> starting the process off again? Try printing the pid each time through
> the inner while loop. See if it changes. Add debugging messages to
> the first if statement so you know when you're killing the process.
>
> Please post a short-but-complete example along with the relevant
> output.
>
> Thanks,
> Paul Lalli


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com