use strict; use warnings; use Tkx; use threads; # ... set up your controls $bar->configure( -orient => "horizontal", -mode => "indeterminate", ); $bar->start(); my $thread = threads->create(sub { system("my.bat"); }); $thread->set_thread_exit_only(1); while ($thread->is_running()) { Tkx::update(); } $progress_bar->stop();

I use basically this code to launch an editor so the user can easily alter the configuration file for my program. The new thread allows Tkx to continue to update while waiting for the user to close the editor window. Depending on what you're doing before you launch your thread, you may not be able to join the thread properly. I leave the thread unjoined and ignore the warnings when my program exits, but it's never executing a ton of stuff this way.

There are probably better ways to manage the thread and what it's executing, but I haven't had time to research it. Leaving the thread unjoined doesn't impact me significantly, as the program I'm doing that on exits on completion. The UI is just for the end user to be able to select some files and feed some data in before the process starts.


In reply to Re: Run a batch file and wait for it to finish by jellisii2
in thread Run a batch file and wait for it to finish by rezeile008

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.