Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

More on Win32::Process not waiting

by Stephen Toney (Sexton)
on Feb 16, 2007 at 11:37 UTC ( [id://600406]=perlquestion: print w/replies, xml ) Need Help??

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;

Replies are listed 'Best First'.
Re: More on Win32::Process not waiting
by chargrill (Parson) on Feb 16, 2007 at 20:12 UTC

    FYI, the following syntax:

    $::mainwin = MainWindow->new (-background => '#b5bfcc');

    ... which is liberally peppered throughout your code is a great way to use global variables and get around the errors you'll encounter when running under use strict. You may want to instead declare your variables with my, i.e.

    my $mainwin = MainWindow->new (-background => '#b5bfcc');

    Regarding your waiting question, my assumption is that at the time your module PPSubs.pm is compiled, values like INFINITE and NORMAL_PRIORITY_CLASS (possibly among others) are undefined when you have the use PPSSubs.pm before the module(s) that define them, i.e. use Win32::Clipboard; and use Win32::Process;. One way around that is to put those two Win32 use lines inside your PPSSubs.pm module.

    And the above anonymous monk is correct, use strict; and use warnings; in your module would help identify that issue.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
      Good advice. Thanks!
Re: More on Win32::Process not waiting
by Anonymous Monk on Feb 16, 2007 at 11:54 UTC
Re: More on Win32::Process not waiting
by GrandFather (Saint) on Feb 16, 2007 at 20:21 UTC
      Sorry, I did my best. You said you wanted runnable code, and without the full Tk stuff it might not have been. After all, I didn't know where the problem was. As for the double spaces, not sure where they came from, probably by copying a file from Windows to Linux. I appreciate the help and will try to do better next time.

        A very useful technique for tracking down a bug when you have no idea where the bug is, is to comment out code until the bug goes away. A very useful technique for getting other people to look at a problem for you is to do, and obviously have done, as much work in tracking the bug down yourself. Actually, in a case like this these are the same technique!

        We generally aren't interested in wading through 300 lines lines of code to find the 10 interesting lines. By cleaning up and condensing your questions to the largest extent you can you learn more yourself, you may actually find the problem yourself and if you end up needing to ask anyway you will get more people looking at the problem and will most likely get better answers.

        In Perl circles lazyness is a virtue, but sometimes you have to work damn hard to be suitably lazy. ;)


        DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://600406]
Approved by graq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found