assassin
assassin

Reputation: 21179

perl script throws compilation error ONLY when running with -d switch

I have a perl script, that runs fine EXCEPT when I try to run it in the debug mode with the -d switch. When I use the -d switch, I get a compilation error like:

Loading DB routines from perl5db.pl version 1.33
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(..\..\bin\testnbestrover1.pl:23):
23:     binmode STDOUT, ":utf8";
Access is denied.
Unknown error
Compilation failed in require at //fbl/NAS/PUB/RapTools/Perl64/lib/Term/ReadLine
/Perl.pm line 65.
 at //fbl/NAS/PUB/RapTools/Perl64/lib/Term/ReadLine/Perl.pm line 65
        Term::ReadLine::Perl::new('Term::ReadLine', 'perldb', 'GLOB(0x382418)',
'GLOB(0x322c30)') called at //fbl/NAS/PUB/RapTools/Perl64/lib/perl5db.pl line 60
68
        DB::setterm called at //fbl/NAS/PUB/RapTools/Perl64/lib/perl5db.pl line
2241
        DB::DB called at ..\..\bin\testnbestrover1.pl line 23
Attempt to reload Term/ReadLine/readline.pm aborted.
Compilation failed in require at //fbl/NAS/PUB/RapTools/Perl64/lib/Term/ReadLine
/Perl.pm line 65.
END failed--call queue aborted at ..\..\bin\testnbestrover1.pl line 65.
 at ..\..\bin\testnbestrover1.pl line 65

This does not happen when I run the script without the -d switch. Any ideas about what may be going wrong here?

Thanks!

EDIT: The same error in Term/ReadLine/Perl.pm line 65 occurs if I comment out the binmode STDOUT, ":utf8"; statement. Upon searching for this specific error on the web, I found someone else had faced the same error when they were redirecting their STDOUT to a file using the ">" operator. Turns out, my perl command was doing the same thing, and when I removed it, the debugger works fine. Seems to be a problem with the specific perl debugger (i.e., per5db.pl version 1.33)?

Upvotes: 5

Views: 944

Answers (1)

Steffen Ullrich
Steffen Ullrich

Reputation: 123461

The stacktrace indicates that the problem comes from Term::ReadLine::Perl which is loaded from the debugger. So no debugging -> no loading of debugger -> no loading of Term::ReadLine::Perl -> no error.

From looking at Term::ReadLine::Perl I guess that the problem is in the line where it tries to load Term::ReadLine::readline which tries to do some stuff with STDIN, STDOUT etc to use it as a terminal. Because this effectively means, that some byte sequences have a special meaning (escape and control codes, like to reset terminal, switch line mode, echo etc) this might infere with your binmode STDOUT settings.

Upvotes: 4

Related Questions