Term::ReadLine reads from the console, not from STDIN. That said, I'm surprised I can't find an option to use STDIO for circumstances such as this one.
I *think* you can do the following:
my $term; if ($ENV{TESTING}) { $term = Term::ReadLine->new('My Application', \*STDIN, \*STDOUT); } else { $term = Term::ReadLine->new('My Application'); }
or even
my $term; if (-t STDIN) { $term = Term::ReadLine->new('My Application'); } else { $term = Term::ReadLine->new('My Application', \*STDIN, \*STDOUT); }
The previous might simplify to:
my $term = Term::ReadLine->new('My Application', \*STDIN, \*STDOUT);
If that doesn't work, the following should (if you only use readline):
use IO::Handle; { package IO::Handle; no warnings 'redefine'; sub readline { my ($self) = @_; my $line = $self->getline(); return unless defined $line; chomp($line); return $line; } } my $term; if (-t STDIN) { $term = Term::ReadLine->new('My Application'); } else { $term = *STDIN; }
In reply to Re: Term::Readline won't accept redirected input
by ikegami
in thread Term::Readline won't accept redirected input
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |