The following simple program works Ok but it has a couple of anomalies that I don't understand. Granted, I'm still fiddling about with Perl/Tk and am still coming to grips with how and when things happen with events... but there are still a few questions.

The main Perl program:

use Win32::Process; use Win32; use Tk; $cmd = "utest.bat"; # Spawned command $mw = MainWindow->new( ); my $mylbl = $mw->Label(-text => 'Click Start')->pack( ); my $olbl = $mw->Label(-text => "(no output)")->pack( ); $mw->Button(-text => "Exit", -command => sub { exit })->pack( ); my $mybtn = $mw->Button( -text => 'Start', -command => \&myjob )->pack( ); MainLoop; sub myjob { $mylbl->configure(-text => 'Running...'); &myjob2; # Option 1 # my @res = `$cmd`; # Option 2 # $olbl->configure(-text => $res[0]); # Option 2 $mylbl->configure(-text => 'Completed!', -foreground => 'red'); } sub myjob2 { Win32::Process::Create($ProcessObj, "C:\\windows\\system32\\notepad.exe", "notepad c:\\tmp\\temp.txt", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj->Wait(INFINITE); } sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); }

The program UTEST.BAT:

@echo off sleep -t 5 echo SLEEP IS DONE

With "Option 1" enabled in the code:

a) When the 'Start' button is pressed and the spawned process is created, the 'Start' button remains pressed. Is there a way the button can be 'restored' to its unpressed state or is there another way that the call should be made?

b) After Notepad starts (and grabs focus, with it's window at the 'front'), within 7 seconds (on my PC) the title bar of the calling program goes dim like it's lost focus. Why is there a delay? Can more than one window have focus at the same time!?

c) Why is the "Running" text never displayed, although the "Completed" text is?

"Option 2" is more like 'reality' for my application. I want to spawn off a call to a non-GUI program and use the output in my Perl/Tk application.

I'm using ActiveState perl v5.8.7 under WinXP-SP2.

Any thoughts or suggestions?


In reply to More Perl/Tk Queries with Spawned Processes under Win32 by ozboomer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.