[Israel.pm] STDIN

Levenglick Dov-RM07994 RM07994 at freescale.com
Sun May 9 05:58:12 PDT 2010


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: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] 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
<RM07994 at freescale.com> 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
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl


More information about the Perl mailing list