http://www.perlmonks.org?node_id=935376


in reply to problem using fork in perl-tk

You mention using a fork, but a piped open or IPC module like IPC::Open3 or IPC-System-Simple will do alot of the work for you. You can also make a set of pipes manually, fork off your code with read and write pipe handles handed off to the fork, but it's alot of details.

One detail you did not mention. Is your background process contained in another script which you can call, or is it in a block of code?

Here is a simple fork example to get you started, otherwise show some code. Also the Tk::ActivityBar module needs to be installed manually, it is used only for a quick demonstration, but it is a problem-prone module.

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ActivityBar; my $mw = MainWindow->new; my $activity = $mw->ActivityBar(-anchor => 'w')->pack(-expand => 1); $mw->Button(-text => 'Start Activity', -command => sub{ $activity->startActivity(); #start the bar my $timer = $mw->after(6500, sub{ $activity->configure('-value' => 0); } ); &do_it; })->pack(); $mw->Button(-text => 'Exit', -command =>sub{ exit })->pack(); MainLoop(); sub do_it{ # you need to fork your command or it will block the gui # from functioning if(fork == 0){ system("date; sleep 2; date; sleep 2; date; sleep 2"); } }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh