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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.