http://qs321.pair.com?node_id=600406

Stephen Toney has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks (especially ikegami and GrandFather):

Thanks to both of you for diagnostic suggestions. The problem turned out to be so strange (to me at least) that I thought it was worth showing here.

This is a Tk app, with the Win32::Process stuff in a separate module named PPSSubs. It turns out that if the "use PPSSubs" is in one place in the main program, Process waits, but in another place, it doesn't. I'd sure like to know the reason for this!

Here's the code -- fully runnable. I'm using ActiveState Perl 5.8.8.819. First the main program:
#! /usr/local/bin/perl use strict; use warnings; #use PPSSubs; # Process doesn't wait if this line is here use Tk; use Tk::ROText; use Win32::Clipboard; use Win32::Process; use PPSSubs; # Process waits if this line is here $::CLIP = Win32::Clipboard(); $::mainwin = MainWindow->new (-background => '#b5bfcc'); $::mainwin->title('MWeb Preprocessing System'); $::mainwin->geometry("-200-200");
$::winheading = $::mainwin->Label ( -background => '#b5bfcc', -foreground => '#0000a0', -font => 'Verdana 14 bold', -text => "MWeb\x{2122} Preprocessing System", ); $::beginbutton = $::mainwin->Button ( -text => 'Begin', -default => 'active', -state => 'active', -font => '{MS Sans Serif} 10 bold', -width => '9', -command => \&MainSub, ); $::settingsbutton = $::mainwin->Button ( -text => 'Settings', -default => 'active', -state => 'active', -font => '{MS Sans Serif} 10 bold', -width => '9', ); $::cancelbutton = $::mainwin->Button ( -text => 'Close', -font => '{MS Sans Serif} 10 bold', -width => '9', -command => sub { exit; } ); $::helplabel = $::mainwin->Label ( -background => '#b5bfcc', -foreground => '#0000a0', -font => 'Arial 9 bold', -text => "For Help go to http://systemsplanning.com/mweb/ppsadmin. +asp", ); $::progresstext = $::mainwin->Scrolled ( 'ROText', -background => '#ffffff', -foreground => '#000000', -font => 'Arial 10', -height => 10, -scrollbars => 'oe', ); $::SPlabel = $::mainwin->Label ( -background => '#b5bfcc', -foreground => '#0000a0', -font => 'Verdana 10', -text => 'Systems Planning', ); $::clientlabel = $::mainwin->Label ( -text => 'Client code', -background => '#ffffff', -font => 'Verdana 10', ); $::clientbox = $::mainwin->Entry ( -background => '#ffffff', -font => 'Verdana 10', -takefocus => 1, ); $::startatlabel = $::mainwin->Label ( -text => 'Program to start at', -background => '#ffffff', -font => 'Verdana 10', ); $::startatbox = $::mainwin->Entry ( -background => '#ffffff', -font => 'Verdana 10', -takefocus => 1, ); $::runonlylabel = $::mainwin->Label ( -text => 'Run only this program', -background => '#ffffff', -font => 'Verdana 10', ); $::runonlybox = $::mainwin->Entry ( -background => '#ffffff', -font => 'Verdana 10', -takefocus => 1, ); $::copylabel = $::mainwin->Label ( -background => '#b5bfcc', -foreground => '#0000a0', -font => 'Verdana 10', -text => 'Copyright © 2000-2007', ); # GEOMETRY MANAGEMENT $::winheading->grid ( -in => $::mainwin, -column => '0', -row => '0', -columnspan => '4', -ipadx => '0', -ipady => '0', -padx => '0', -pady => '0', -rowspan => '1', -sticky => '' ); $::beginbutton->grid ( -in => $::mainwin, -column => '0', -row => '1', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '0', -pady => '0', -rowspan => '1', -sticky => 'e' ); $::settingsbutton->grid ( -in => $::mainwin, -column => '2', -row => '1', -columnspan => '1', -ipadx => '4', -ipady => '0', -padx => '0', -pady => '0', -rowspan => '1', -sticky => '' ); $::cancelbutton->grid ( -in => $::mainwin, -column => '3', -row => '1', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '0', -pady => '0', -rowspan => '1', -sticky => 'w' ); $::helplabel->grid ( -in => $::mainwin, -column => '0', -row => '2', -columnspan => '4', -ipadx => '0', -ipady => '0', -padx => '0', -pady => '0', -rowspan => '1', -sticky => '' ); $::progresstext->grid ( -in => $::mainwin, -column => '0', -row => '4', -columnspan => '4', -ipadx => '0', -ipady => '0', -padx => '0', -pady => '0', -rowspan => '1', -sticky => '' ); $::SPlabel->grid ( -in => $::mainwin, -column => '0', -row => '7', -columnspan => '2', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => 'w' ); $::clientlabel->grid ( -in => $::mainwin, -column => '1', -row => '5', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => '' ); $::clientbox->grid ( -in => $::mainwin, -column => '2', -row => '5', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => '' ); $::startatlabel->grid ( -in => $::mainwin, -column => '1', -row => '6', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => '' ); $::startatbox->grid ( -in => $::mainwin, -column => '2', -row => '6', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => '' ); $::runonlylabel->grid ( -in => $::mainwin, -column => '1', -row => '7', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => '' ); $::runonlybox->grid ( -in => $::mainwin, -column => '2', -row => '7', -columnspan => '1', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => '' ); $::copylabel->grid ( -in => $::mainwin, -column => '2', -row => '7', -columnspan => '2', -ipadx => '0', -ipady => '0', -padx => '2', -pady => '2', -rowspan => '1', -sticky => 'e' ); $::mainwin->gridRowconfigure(0, -weight => 0, -minsize => 40, -pad => +0); $::mainwin->gridRowconfigure(1, -weight => 0, -minsize => 60, -pad => +0); $::mainwin->gridRowconfigure(2, -weight => 0, -minsize => 20, -pad => +0); $::mainwin->gridRowconfigure(3, -weight => 0, -minsize => 20, -pad => +0); $::mainwin->gridRowconfigure(4, -weight => 0, -minsize => 60, -pad => +0); $::mainwin->gridRowconfigure(5, -weight => 0, -minsize => 30, -pad => +0); $::mainwin->gridRowconfigure(6, -weight => 0, -minsize => 30, -pad => +0); $::mainwin->gridColumnconfigure(0, -weight => 0, -minsize => 170, -pad + => 0); $::mainwin->gridColumnconfigure(1, -weight => 0, -minsize => 170, -pad + => 0); $::mainwin->gridColumnconfigure(2, -weight => 0, -minsize => 170, -pad + => 0); $::mainwin->gridColumnconfigure(3, -weight => 0, -minsize => 170, -pad + => 0); $::mainwin->bind('<Return>' => [$::beginbutton => 'Invoke']);
Tk::MainLoop;
Here is PPSSubs.pm:
#MainSub sub MainSub { $::CLIP->Empty(); print "before creating process\n"; my $ProcessObj; Win32::Process::Create($ProcessObj, "c:\\windows\\system32\\notepad.exe", "notepad", 0, NORMAL_PRIORITY_CLASS, ".") || die Win32ProcessError(); print "before wait\n"; $ProcessObj->Wait(INFINITE); print "after wait\n"; } #MainSub sub Win32ProcessError { print Win32::FormatMessage(Win32::GetLastError()); } 1;