http://qs1969.pair.com?node_id=127064

csotzing has asked for the wisdom of the Perl Monks concerning the following question:

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.