Just what I'm looking for. I'll let you know how it works out

 
Best Regards,
Dov Levenglick
SmartDSP OS Development Leader

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of 
Gaal Yahas
Sent: Sunday, May 09, 2010 14:58
To: Perl in Israel
Subject: Re: [Israel.pm] STDIN

What do you want your program to be doing, if not to block?

stdin is just another file. You can put it in nonblocking mode, though
that probably means you have to give up using readline (<>) and read
on it (use sysread instead). I'm guessing something like (totally
untested, adapted from fcntl in perlfunc):

use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
my $flags = fcntl(\*STDIN, F_GETFL, 0)
                               or die "Can't get flags for stdin: $!\n";
$flags = fcntl(\*STDIN, F_SETFL, $flags | O_NONBLOCK)
                               or die "Can't set flags for stdin: $!\n";


Of course, now you also need to think up a scheme for what constitutes
a full applicative read: it can be some delimiter, message size, or
perhaps a timeout.

On Sun, May 9, 2010 at 2:11 PM, Levenglick Dov-RM07994
<[email protected]> wrote:
> Hi,
> Is there a way to pipe the keyboard input (STDIN) to a subroutine without 
> forking or blocking the main program?
>
>
> Best Regards,
> Dov Levenglick
> ΓΌ SAVE PAPER - THINK BEFORE YOU PRINT
>
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <[email protected]>
http://gaal.livejournal.com/
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to