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

Hi all, i have a Tk-program with a start-button and a stop-button to start or stop a pipe to an external programm. The start-botton works fine and start the pipe for the external-program. But if i click on the stop-button the program is hanging. I dont know how i can stop the pipe over the stop-button without hanging the program. The goal is to start or stop the pipe on every click on the certain button. May be anybody has an idea? It would be very very nice...
use Tk; #================================================ # Main-Window #================================================ $HF = new MainWindow (-title => "Main-Window"); $HF->geometry('100x100'); #================================================== # Buttons #================================================== $BtnStart = $HF->Button ( -text=>"START", -command => \&ext, -borderwidth => 2, -relief => raised, )->pack(); $BtnStop = $HF->Button ( -text=>"STOP ", -command => sub{close (FH);$HF->update();}, )->pack(); #================================================ # Tk-End #================================================ MainLoop(); #================================================ # SUB-Programs #================================================ sub ext { #xxxx Pipe to the external programm open(FH, "c:\\extern.exe |"); while($tp=<FH>) { print "\n$tp"; $HF->update(); } }
best regards, michbach

Replies are listed 'Best First'.
Re: stop pipe
by zentara (Cardinal) on Mar 29, 2009 at 16:43 UTC
      Omg, that looks not easy. I have to read all first and try to find a resolution. Thanks for try to help me..best,regards michbach
Re: stop pipe
by samtregar (Abbot) on Mar 29, 2009 at 18:22 UTC
    Instead of closing the filehandle, how about killing the subprocess with kill()? I have no idea if that works on Windows but it's what I'd try if I had this problem on Linux.

    -sam

      tx, samtregar but "closing the filehandle" was only my first idea to open and close that pipe as i want only by clicking on the buttons. But it dont seems so easy. I can open the pipe easy but its not possible in this way to close the process... It seems to be a much more complex process :-(