Re: STDIN on the fileevent handle
- From: zentara <zentara@xxxxxxxxxxxxxx>
- Date: Thu, 18 May 2006 12:52:06 GMT
On 17 May 2006 11:27:59 -0700, "CORBA" <mkess1021@xxxxxxxxx> wrote:
Hello all......snip.......
I have been on here a few times and the help has been tremendous. So
when I ran into a recent roadblock, I thought I'd run it by the group
and see if anyone knows the solution.
I am using STDIN to feed a fileevent handle and populate a status
board. So, for example, if I type in one of four acceptable commands
to STDIN, then my status board will take a certain action based on the
input command.
But for a reason I don't understand, this does not work with piped
input. All the commands are correct and I can verify that the status
board does get the input. However, there are two problems. #1) The
widgets never get displayed to the status board - the top level widget
is created but nothing is done with "readinput", my fileevent call.
#2) After recieving a legit command, the status board seems to think it
gets endless messages and continues to read blank lines. It is almost
as if it thinks there is input available and just continually reads.
Yeah, STDIN is a bit tricky to deal with. First STDIN can either be a
pipe or the keyboard, but it takes some doing to make it accept both
simultaneously. For instance if you run the program with a pipe, you
won't get the keyboard back until you close STDIN and reopen it
open (STDIN, "</dev/tty") or die $!;
The other thing is that STDIN never closes, unless you do it, so you
get the "endless messages" problem.
There are solutions. See
http://perlmonks.org?node_id=439053
This runs "./sender | ./write_me"
You might want to look at using sockets instead of STDIN.
Or you might want to look at IPC::Open3 instead of trying to run piped
opens. What is your overall objective?
############# sender #################################
#!/usr/bin/perl
$|++;
while(1){
print "xterm\n";
sleep 5;
}
############ write_me ################################
#!/usr/bin/perl
use warnings;
use Tk;
my $mw = MainWindow->new;
my $top = $mw->Toplevel();
$mw->withdraw;
$top->geometry( '100x100+100+100' );
$top->title("Test Connection Status Board");
$top->focusmodel ("active");
$top->waitVisibility;
# The waiting game
$mw->fileevent(\*STDIN, readable => [\&readinput, $top]);
MainLoop;
sub readinput {
# Process input
my($widget) = @ARG;
# Chop out the action and values
my $ARG = <STDIN>;
chomp $ARG;
if ((length $ARG) == 0) {
print "no length $tmp\n";
$tmp++;
return;
}
my @parts = split /:/, $ARG;
my $action = $parts[0];
my $value = $parts[1];
if ($value) {
chomp $value;
}
print "action ->$action\n";
if(fork() == 0){exec( $action )}
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
.
- References:
- STDIN on the fileevent handle
- From: CORBA
- STDIN on the fileevent handle
- Prev by Date: Re: How to get a simple message box?
- Next by Date: Re: 2-way communication
- Previous by thread: Re: STDIN on the fileevent handle
- Next by thread: JComboBox problem
- Index(es):
Relevant Pages
|