Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: problem using fork in perl-tk

by zentara (Archbishop)
on Nov 02, 2011 at 12:32 UTC ( #935376=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935376]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-02-25 19:24 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (368 votes). Check out past polls.