in reply to More Perl/Tk Queries with Spawned Processes under Win32
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 :)
|
|---|