http://qs321.pair.com?node_id=1064595

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

Hi Monkies, I am making a program in windows that would open a command line and monitor (read) its output, problem is it hangs after it read thru all the buffer. I have a similar code that works fine in linux, but hangs in windows.



#!/usr/bin/perl -w use strict; use Gtk2 '-init'; use Gtk2::Helper; use Data::Dumper; use IPC::Open2; use FileHandle; # file handles my $wfh = FileHandle->new(); my $rfh = FileHandle->new(); open2($rfh,$wfh, "C:\\Windows\\System32\\cmd.exe"); my $tag = Gtk2::Helper->add_watch($rfh->fileno(), 'in',\&preview_call) +; my $window = Gtk2::Window->new(); $window->signal_connect("destroy",sub{Gtk2->main_quit();}); $window->set_size_request(200,200); my $vbox = Gtk2::VBox->new(); $window->add($vbox); my $button = Gtk2::Button->new("TEST"); $button->signal_connect('clicked'=>sub{ mysub(); }); $vbox->pack_start($button,0,0,0); $window->show_all(); Gtk2->main(); sub preview_call { my $buffer; my $rl = sysread($rfh,$buffer,1); if(defined($rl)){ print "$rl + $buffer\n"; while (Gtk2->events_pending()) {Gtk2->main_iteration();} return 1; }else{ print "undefined\n"; return 0; } } sub mysub { print $wfh "echo wako\n"; }


I think the problem is in the Gtk2::Helper->add_watch. Help! This shouldnt freeze the window, i should be able to press the button and the monitor should be able to see the echo command under the mysub subroutine

Mabuhay Civil Engineers! :D