Hello!
Simply put, I'm writing a perl/tk gui, containing a text widget and a Run button. My intent is for Run to open a pipe to the output of another perl script of mine. I want to read the output and insert it into the text widget. My other perl script (test.pl) takes a while to run, so I want to make sure that I'm using non-blocking I/O and a callback for when the pipe is readable, so that my gui doesn't freeze. So far I've tried using Tk's fileevent and the Tk::IO module, both without success. (I believe the Tk::IO's exec creates a separate thread for running my other script.) Here are some snippets from my latest attempt:
use Tk::IO;
# callback for 'Run' Button
sub RunCB {
$fh = new Tk::IO->new(-linecommand => \&guiReadTestHandle,
-childcommand => \&guiCloseTestHandle);
$fh->exec("test.pl");
}
# callback for when $fh is readable<BR>
sub guiReadTestHandle {
if (<$fh>) {
$txtRunRslt->insert(end, $data);
}
}
# callback for when $fh reaches EOF
sub guiCloseTestHandle {
$fh->close();
}
When I run the program and click 'Run', I get the message
'-' is not recognized as an internal or external command, operable program or batch file., then the guiCloseTestHandle is called, closing the filehandle. I'm running on Win2K, with ActivePerl 5.6.1. The Tk::IO version appears to be 3.038. If anyone has any information on what I'm doing wrong, or how I can better achieve this, I would really appreciate it! Thanks, all.
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.