Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

fileevent or Tk::IO with pipes

by csotzing (Sexton)
on Nov 23, 2001 at 09:48 UTC ( #127064=perlquestion: print w/replies, xml ) Need Help??

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

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 ( 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(""); } # 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.

Replies are listed 'Best First'.
Re: fileevent or Tk::IO with pipes
by mkmcconn (Chaplain) on Nov 23, 2001 at 10:11 UTC
    You may need to change the line to invoke perl explicitly:

    (There's almost certainly a better way to do that, if it works.)

Re: fileevent or Tk::IO with pipes
by Anonymous Monk on Nov 23, 2001 at 19:05 UTC
    Thanks for the suggestion... unfortunately, it didn't work. I've put the code for my gui, and the sample script which the gui is supposed to run on-line. If it helps, the code is located here:
Re: fileevent or Tk::IO with pipes
by smackdab (Pilgrim) on Dec 09, 2001 at 09:33 UTC
    There is a good article that explains the problems you are running into. I ran into them also...

    The article is by, Stephen Lidie, he will have his advanced Perl/Tk book out this month (800 pages !!!)

    This is one of the many broken things with have to do some other form of communication. I choose to spawn a process and use network sockets, but you could choose a pipe or shared memory or ???

    It would be nice if we could use threads or fork(), but they are also broken in Win32 ;-(

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://127064]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-06-04 00:06 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (17 votes). Check out past polls.