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");
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.