#!/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"; }