Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perlmonks,

I'm trying to use this perl module v0.02 and I'm getting an odd result. Initially, the script doesn't work and dies with a readline issue. Then I run it through the debugger and it automatically starts working. Any ideas? Could this be a version issue?

$ sh.pl <initialization successful> Can't call method "readline" on an undefined value at Term/Shell.pm li +ne 104. $ perl5.26.1 -d ./sh.pl Loading DB routines from perl5db.pl version 1.51 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. 19: my %options = (); 20: GetOptions(\%options, 24: usage(0) if $options{help}; 26: my $shell = SH::Shell->new; DB<1> <initialization successful> 28: $shell->cmdloop; DB<1> n shell> q # sh.pl <initialization successful> shell> q

Thanks for your help--very much appreciated !!!

Best,

Michael

Replies are listed 'Best First'.
Re: Term::Shell readline
by LanX (Saint) on Mar 09, 2023 at 00:09 UTC
    debugging a Term::ReadLine application inside the debugger is very tricky, because it's also needing Term:ReadLine. That's like transporting a motor-scooter on a motor-scooter.°

    I'm surprised you can do anything meaningful now, but if you say it "works", then this means the debugger is providing the right readline environment.

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

    °) well I've seen this in Vietnam but that's another story ...

      debugging a Term::ReadLine application inside the debugger is very tricky, because it's also needing Term:ReadLine.

      Would rebinding the application STDIN/STDOUT to some other terminal (or a unix domain socket) work?

      PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
        Yes.

        I think Discipulus and me had this discussion before. (I'll dig °)

        The debugger has by itself the possibility to communicate via a socket, that's how debugging is implemented inside emacs and other IDEs.

        Hence the easiest way should be to start the debugger inside an IDE and wrap the app inside it's own terminal.

        Cheers Rolf
        (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
        Wikisyntax for the Monastery

        update

        °) Here: How to perldebug a Term::ReadLine application (sic ... added to my profile page now)

Re: Term::Shell readline
by haj (Vicar) on Mar 08, 2023 at 22:07 UTC

    Version 0.02 of Term::Shell is from 2007. So yeah, upgrading it might be a start.

    If the script dies from the commandline and works from the debugger, then probably the debugger brings a library into the mix which makes the script work because it is there before you create your object. Your example code uses SH::Shell, a module unknown to me (and to CPAN), so I can't help much further.

    A shot in the dark: Do you have Term::ReadLine::Gnu installed? Or any other Term::Readline backends?

      Thank you very much, haj! I have requested a module version upgrade! That's a good point which I should have mentioned. SH::Shell is just a company-specific perl module which inherits from Term::Shell. I am not sure whether I have those installed. Is there an easy way to check ?

      package SH:Shell; use base qw(Term::Shell); sub init { ## good stuff of course }

        When I list the subroutines in the debugger, it seems it's listed, so maybe I just need to force load this in the init subroutine?

        DB<2> S Term::ReadLine Term::ReadLine::BEGIN Term::ReadLine::Gnu::AU::AUTOLOAD Term::ReadLine::Gnu::AU::BEGIN Term::ReadLine::Gnu::AU::__ANON__[//ms/dist/perl5/PROJ/Term-ReadLine-G +nu/1.35-6.2-5.26/lib/perl5/Term/ReadLine/Gnu.pm:848] Term::ReadLine::Gnu::AddHistory Term::ReadLine::Gnu::Attribs Term::ReadLine::Gnu::BEGIN Term::ReadLine::Gnu::CallbackHandlerInstall Term::ReadLine::Gnu::DESTROY Term::ReadLine::Gnu::Features Term::ReadLine::Gnu::GetHistory Term::ReadLine::Gnu::IN Term::ReadLine::Gnu::ISFUNC Term::ReadLine::Gnu::ISKMAP Term::ReadLine::Gnu::ISMACR Term::ReadLine::Gnu::MULT_MATCH Term::ReadLine::Gnu::MinLine Term::ReadLine::Gnu::NO_MATCH Term::ReadLine::Gnu::OUT