Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk - sub not executed (Windows) 1

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

The KILL_MON sub below does not seem to get executed whem a STOP or QUIT buttons are pushed:

my $but1 = $mw -> Button(-text=>"Start nettest", -command =>\&start)-> pack(qw/-side left/); #Start button
my $but2 = $mw -> Button(-text=>"Stop nettest", -command =>sub{$STOP=1;\&KILL_MON})-> pack(qw/-side left -padx 20/);#Start button
my $but3 = $mw -> Button(-text=>"QUIT", -command =>sub{\&KILL_MON;$mw->destroy})-> pack(qw/-side left/);#Quit button

MainLoop; #This function will be executed when the button is pushed
################################################################################
sub KILL_MON
{
print STDOUT "NOW in KILL_MON\n";
&disp("\nNow cleaning up a bit both filesystems . . .\n");
close TMPFILE1;
close LOGFILE;

$Machine = "\\\\.";
$CLASS = "winmgmts:{impersonationLevel=impersonate}$Machine\\Root\\cimv2";
$WMI = Win32::OLE->GetObject( $CLASS ) || die;
foreach my $Proc ( in( $WMI->InstancesOf( "Win32_Process" ) ) ) {
my $PROCNAME = $Proc->{Name} ;
if ( $PROCNAME =~ /ftp/) {
$FTPID = $Proc->{ProcessID};
}
}
kill 9 => $FTPID if ($FTPID);
if ($LARGEST && $BRISQUE eq "YES" && $STARTED eq "YES") {
sleep 1;
system("ftp -s:c:\\temp\\MONSCRIPT5 $REMOTE_HOST c:\\temp\\END");
} elsif ($LARGEST && $STARTED eq "YES") {
sleep 1;
system("del \"\\\\$REMOTE_HOST\\$LARGEST\\100MB\"");
}
if ($STOP) {
return;
} else {
exit 1;
}
}

##################
$STOP=1 get's it's value if STOP button is pushed,$mw->destroy is executed if QUIT button is pushed,nut KILL_MON seems never to get activated.
Any ideas why ?


Long live king Moshiach !
 
I saw the problem right away:

Code:
my $but1 = $mw -> Button(-text=>"Start nettest", -command =>[COLOR=blue]\&start[/color])-> pack(qw/-side left/);         #Start button
my $but2 = $mw -> Button(-text=>"Stop nettest", -command =>sub{$STOP=1;[COLOR=red]\&KILL_MON[/color]})-> pack(qw/-side left -padx 20/);#Start button
my $but3 = $mw -> Button(-text=>"QUIT", -command =>sub{[COLOR=red]\&KILL_MON;[/color]$mw->destroy})-> pack(qw/-side left/);#Quit button

Get rid of the backslash before the & for those two subs. When you use a backslash like that, you create a reference to something, in this case, a coderef.

When you use the "-command => \&sub" syntax, you make a coderef for -command. It would be the same as having "-command => sub {...}" and putting all the stuff that was in \&sub into that anonymous subroutine.

In your Stop and Quit buttons, you declared an anonymous subroutine, so it should be treated like any other subroutine. So, drop the \ before the & inside of those subs.

I hope that made any sense at all.

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top