Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How to perldebug a Term::ReadLine application (the other way round)

by LanX (Saint)
on Dec 01, 2014 at 16:21 UTC ( [id://1108844]=note: print w/replies, xml ) Need Help??


in reply to How to perldebug a Term::ReadLine application

Another ... maybe saner way ... to do it is to attach the application explicitely to another TTY.

Ideally a module could sense if it's run within the debugger and automatically set the TTY.

For instance xterm -e perl -e 'print `tty`;sleep' will show the TTY of this terminal ( /dev/pts/5 in this case) and sleep indefintely to not disturb the TTY output.

the following script hardcodes that TTY into TRL:

use Term::ReadLine; my $tty='/dev/pts/5'; open my $out,'>',$tty; open my $in,'<',$tty; my $term = Term::ReadLine->new('Simple Perl calc',$in,$out); my $prompt = "Enter code: "; my $OUT = $term->OUT || \*STDOUT; while ( $_ = $term->readline($prompt) ) { my $res = eval($_); warn $@ if $@; print $OUT $res, "\n" unless $@; $term->addhistory($_) if /\S/; }

I have problems to figure out a nice way to automize it. Ideally I'd get the TTY of the spawned xterm returned.

The only thing I figured out at the moment is to look into the proces table

> ls -l /proc/31965/fd/ insgesamt 0 lrwx------ 1 lanx lanx 64 Dez 1 17:18 0 -> /dev/pts/5 lrwx------ 1 lanx lanx 64 Dez 1 17:18 1 -> /dev/pts/5 lrwx------ 1 lanx lanx 64 Dez 1 17:18 2 -> /dev/pts/5

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

Replies are listed 'Best First'.
Re^2: How to perldebug a Term::ReadLine application (the other way round)
by RonW (Parson) on Dec 01, 2014 at 18:21 UTC

    Why not:

    DEBUG_TTY=`tty` xterm -e perl -d ./myRLprog.pl

    Then in myRLprog.pl, include:

    if (defined $ENV{DEBUG_TTY}) { my $tty = $ENV{DEBUG_TTY}; open my $out,'>',$tty; open my $in,'<',$tty; my $term = Term::ReadLine->new('Simple Perl calc',$in,$out); } else { ...; }

    Would that work?

      well this works

      PERLDB_OPTS="ReadLine=0" MASTER_TTY=`tty` xterm -e perl -d calc_TRL.pl

      with

      otherwise the debugger starts spontaneously to write to the master terminal, IMHO a bug somewhere between debugger and TRL.

      My former approach to redirect the app's tty to a slave terminal has the advantage to run without lost of features in IDEs like emacs.

      The slave terminal can also be an extra sub-window within the IDE running a terminal emulation.

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re^2: How to perldebug a Term::ReadLine application (the other way round)
by RonW (Parson) on Dec 01, 2014 at 22:06 UTC

    As another possibility, maybe:

    TEMP=$(mktemp /tmp/temporary-file.XXXXXXXX) xterm -e bash -c "tty >$TEMP; sleep 24h" sleep 1 # give time for tty to run exec 9<$TEMP read -u 9 SLAVE_TTY exec 9<&- export SLAVE_TTY perl myRLprog.pl

    This can be done in a more Perl-ish way, but this is the general idea. (Except for xterm, tty and perl, the commands are built into bash.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1108844]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-28 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found