M
Michael Goerz
Consider the following simplified script:
#!/usr/bin/perl -w
use strict;
use Gtk2;
sub stdin_handler {
my $line = <STDIN>;
if (defined($line)){
print "process: $line";
}
}
Gtk2->init;
Glib::IO->add_watch (fileno(STDIN), ['in'], sub{stdin_handler('dummy')});
Gtk2->main;
#EOF
What I want this to do is to handle commands received from STDIN, line
by line. In the real program, it's going to be data lines that will be
plotted real-time on a GUI.
When I just start the program, and then manually enter input on the
shell, it works as it should: for every line that I type, as soon as I
hit enter, I get back "process: line". However, when I use 'cat' to feed
data to the program (or pipe into it from anywhere else), it just takes
the first line of input, returns that, and then just sits there doing
nothing. What can I do to process STDIN line by line, treating each line
as a single event?
I can't slurp the input with @lines = <STDIN>, that reads all the input,
but the program will wait until EOF before it does any processing on the
GUI--I don't get the real-time plotting.
Any suggestions?
Michael
#!/usr/bin/perl -w
use strict;
use Gtk2;
sub stdin_handler {
my $line = <STDIN>;
if (defined($line)){
print "process: $line";
}
}
Gtk2->init;
Glib::IO->add_watch (fileno(STDIN), ['in'], sub{stdin_handler('dummy')});
Gtk2->main;
#EOF
What I want this to do is to handle commands received from STDIN, line
by line. In the real program, it's going to be data lines that will be
plotted real-time on a GUI.
When I just start the program, and then manually enter input on the
shell, it works as it should: for every line that I type, as soon as I
hit enter, I get back "process: line". However, when I use 'cat' to feed
data to the program (or pipe into it from anywhere else), it just takes
the first line of input, returns that, and then just sits there doing
nothing. What can I do to process STDIN line by line, treating each line
as a single event?
I can't slurp the input with @lines = <STDIN>, that reads all the input,
but the program will wait until EOF before it does any processing on the
GUI--I don't get the real-time plotting.
Any suggestions?
Michael