Hi Bulk88,
I have updated my codes and added a queuing system to handle the output chronologically.
I have had problems when sending a single command multiple times at very fast speeds. I have been using this for creating a "live view" for a camera. The previous code was unable to read the output chronologically because of the time it takes for the camera to send a reply. With that I came up with a simple queue system to read all output (depending on the size of the output) and chop the output into lines, and push each line to the array.
Then I have a another sub that reads 1 line from the array, this is being read continuously.

Sample Code Below
#!/usr/bin/perl -w use strict; use Gtk2 '-init'; use Gtk2::Helper; use Data::Dumper; use FileHandle; use IPC::Open2; use Win32API::File; use Win32::API; my @queue; { my $api; die "PeekNamedPipe" if ! ($api= Win32::API->Import("kernel32", " BOOL PeekNamedPipe( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage );")); } my $wfh = FileHandle->new(); my $rfh = FileHandle->new(); open2($rfh,$wfh,"C:\\Windows\\System32\\cmd.exe"); my $hnd = Win32API::File::FdGetOsFHandle($rfh->fileno()); if($hnd == Win32API::File::INVALID_HANDLE_VALUE()){ die "bad hnd"; } my $tag = Glib::Timeout->add(10,\&repeat_call); my $window = Gtk2::Window->new(); $window->signal_connect("destroy",sub{Gtk2->main_quit();}); my $hbox = Gtk2::VBox->new(); $window->add($hbox); my $button = Gtk2::Button->new("DIR"); $button->signal_connect('clicked'=>sub{ print $wfh "dir\n"; }); $hbox->pack_start($button,0,0,0); $button = Gtk2::Button->new("TIME"); $button->signal_connect('clicked'=>sub{ print $wfh "time /t\n"; }); $hbox->pack_start($button,0,0,0); $window->show_all(); Gtk2->main(); sub repeat_call { my $bAvail = 0; my $ret = 0; my $buffer; $bAvail = "\x00" x 4; $ret = PeekNamedPipe($hnd,undef,0,undef,$bAvail,undef); if(!$ret) { my $err = Win32::GetLastError(); die "PNP failed $err $^E"; } $bAvail = unpack('L', $bAvail) . "\n"; if($bAvail > 0) { sysread($rfh,$buffer,$bAvail); chomp($buffer); my (@q) = split(/\n/,$buffer); foreach my $qq (@q){ chomp($qq); push @queue, $qq; } } action_call(); while (Gtk2->events_pending()) {Gtk2->main_iteration();} return 1; } sub action_call { my $count = @queue; if($count){ my $line = shift(@queue); print $line . "\n"; } }

This is a bit slow, but still does the work! Thanks again for your inputs! BTW I added this as a reference for my blog. Thanks!
Mabuhay Civil Engineers! :D

In reply to Re^3: ActivePerl Gtk2::Helper Hangs by renegadex
in thread ActivePerl Gtk2::Helper Hangs by renegadex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.