If you have a threaded perl, then you could start a thread at the start of your program and have it sit in a $q_cmds->dequeue() (Thread::Queue)loop. The button then uses $q_cmds->enqueue() to pass commands and parameters (or simply a "DO IT NOW" flag if the call is always the same) to the background thread and have it perform the backticks, system or IPC::Open2/3 as appropriate.

The main thread would then call $q_results->pending(); every now and again to check if the results are ready and $q_results->dequeue() to fetch and display them. That would allow the gui to remain responsive while the system commands are processed, which I assume is your aim.

Note: You need to create two queues before the thread is created, one foreground->background for the commands and one background->foreground for the results.

If the program your are calling has an intereactive mode, then you might be able to avoid the overhead of re-loading the program each time by using something like Expect or Expect::Simple in the background thread.

If the programs you are callling vary, you might be able to drive your shell this way, but the advantage diminishes as you would still be reloading the program itself each time.

Whether any of the effort is worth it will depend on how many and how long running the command you are running are, and whether there is anything that the foreground thread can logically be doing whilst the background thread is running.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

In reply to Re: Avoiding fork by BrowserUk
in thread Avoiding fork by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.