Well, here we go... another version that uses the 'system' call (thanks, BrowserUk)...

use Win32::Process; use Win32; use Tk; $cmd = "utest.bat"; # Spawned command $mw = MainWindow->new( ); my $mylbl = $mw->Label(-text => 'Click Start')->pack( ); my $byebtn = $mw->Button(-text => "Exit", -command => sub { exit })->p +ack( ); my $mybtn = $mw->Button( -text => 'Start', -command => \&myjob )->pack( ); &reset_disp; MainLoop; sub myjob # ------------------------------ { &create_file_sys; &show_file_sys; &reset_disp; } sub create_file # ------------------------------ { $mylbl->configure(-text => 'Running...'); $mw->update; Win32::Process::Create(my $ProcessObj, "c:\\windows\\system32\\cmd.exe", "cmd /c utest.bat del.me", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $mw->update () while $ProcessObj->GetExitCode($exitcode), $exitcode + == 259; } sub create_file_sys # ------------------------------ { $mylbl->configure(-text => 'Running...'); $byebtn->configure(-state => disabled); $mw->update; my $pid = system 1, 'utest.bat', 'del.me'; waitpid $pid, 0; } sub show_file # ------------------------------ { $mylbl->configure(-text => 'Completed!', -foreground => 'red'); $mw->update; Win32::Process::Create($ProcessObj2, "C:\\windows\\system32\\notepad.exe", "notepad del.me", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj2->Wait(INFINITE); } sub show_file_sys # ------------------------------ { $mylbl->configure(-text => 'Completed!', -foreground => 'red'); $byebtn->configure(-state => disabled); $mw->update; my $pid = system 1, 'notepad', 'del.me'; waitpid $pid, 0; } sub reset_disp # ------------------------------ { $mylbl->configure(-text => 'Click Start', -foreground => 'black'); $byebtn->configure(-state => active); $mw->update; }

...and the (trivially) revised UTEST.BAT:

@echo off :sleep -t 2 echo SLEEP IS DONE at %TIME% > %1

I'm still struggling a mite with the 'events' but I think I have something that works the way I want it to. An old thought of mine returns: if you can't get things to work, over-modularize it... and that's what I've done. At least it helps my understanding... and it does what I want.

As usual, the Monks have been very helpful... Thanks one 'n all :)


In reply to Re: More Perl/Tk Queries with Spawned Processes under Win32 by ozboomer
in thread 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.