diff options
author | Gisle Aas <gisle@activestate.com> | 2010-05-01 22:49:10 -0700 |
---|---|---|
committer | Gisle Aas <gisle@aas.no> | 2010-05-02 08:58:16 +0200 |
commit | d956618a38976d4304e0ac23da739ba2aee25f07 (patch) | |
tree | 64112e3267a41a41367697b57125332d25f2c326 | |
parent | f5d41823bbea2258a17f2f1d1cb3518b46ab3562 (diff) | |
download | perl-d956618a38976d4304e0ac23da739ba2aee25f07.tar.gz |
Make Term::ReadLine::findConsole fall back to STDIN if /dev/tty can't be opened
-rw-r--r-- | lib/Term/ReadLine.pm | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/lib/Term/ReadLine.pm b/lib/Term/ReadLine.pm index 29acb84901..7913b917f0 100644 --- a/lib/Term/ReadLine.pm +++ b/lib/Term/ReadLine.pm @@ -156,22 +156,6 @@ empty, the best available package is loaded. (Note that processing of C<PERL_RL> for ornaments is in the discretion of the particular used C<Term::ReadLine::*> package). -=head1 CAVEATS - -It seems that using Term::ReadLine from Emacs minibuffer doesn't work -quite right and one will get an error message like - - Cannot open /dev/tty for read at ... - -One possible workaround for this is to explicitly open /dev/tty like this - - open (FH, "/dev/tty" ) - or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }'; - die $@ if $@; - close (FH); - -or you can try using the 4-argument form of Term::ReadLine->new(). - =cut use strict; @@ -235,6 +219,10 @@ sub findConsole { $consoleOUT = $console unless defined $consoleOUT; $console = "&STDIN" unless defined $console; + if ($console eq "/dev/tty" && !open(my $fh, "<", $console)) { + $console = "&STDIN"; + undef($consoleOUT); + } if (!defined $consoleOUT) { $consoleOUT = defined fileno(STDERR) && $^O ne 'MSWin32' ? "&STDERR" : "&STDOUT"; } |