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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |