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

Testing terminal programs within emacs (or other IDEs)

by LanX (Saint)
on Nov 28, 2014 at 19:00 UTC ( [id://1108664]=perlquestion: print w/replies, xml ) Need Help??

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

Hi

does someone have a clever idea how to interactivly run the currently edited program within a terminal emulation without loosing potential error output?

Especially Term::ReadLine is unusable within compilation-mode, which opens a new pane showing the interaction with the program.

Compilation mode has no terminal emulation (AFAIK), which means potential errors and output is displayed but input doesn't get to the process.

3 ideas come to mind:

  1. augment compilation mode to incorparate term-mode?
  2. Term::ReadLine allows defining explicit IN and OUT handles which may be redirected to a separate xterm window?
  3. like 2., but redirect output to a new splitted pane within emacs
Curious for input, especially for insights if and how other IDEs solve this.

Cheers Rolf

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

glossary:
I use "pane" for a sub-window within the main window, i.e. what emacs calls a "window" and mozilla calls a "frame"

update

for what it's worth, it's possible to run a term script with "M-x term path-to-script" within emacs. This would not only need another keybinding but any special handling of error messages is lost than.

  • Comment on Testing terminal programs within emacs (or other IDEs)

Replies are listed 'Best First'.
Re: Testing terminal programs within emacs (SOLVED)
by LanX (Saint) on Nov 29, 2014 at 21:41 UTC
    > Term::ReadLine allows defining explicit IN and OUT handles which may be redirected to a separate xterm window?

    tried this but wasn't sufficiently reliable, (but this couldhave been be caused by gnome-terminal weirdness)

    The following hack works with xterm , put it at the very beginning of your program.

    It restarts the program within a separate xterm-window but redirects STDERR to the parent process.

    This allows running a terminal script from within emacs and should be easily adapted to other environments using l/unix.

    All STDERR warnings show within emacs and are clickable to navigate to source file/line.

    my $ptty=$ARGV[0]; if ($ENV{INSIDE_EMACS}) { my $tty=`tty`; delete $ENV{INSIDE_EMACS}; warn "restart in xterm $0 $tty\n"; my $x=`xterm -e '/usr/bin/perl $0 $tty'`; warn "xterm closed\n"; exit; } elsif ($ptty) { close STDERR; open STDERR,">",$ptty; local $\="\n"; warn "redirecting STDERR to $ptty\n"; $|=1; }

    This approach can also be used by the perldebugger when debugging another Term::ReadLine application

    When sufficiently tested this logic can be put into a separate module RunXTerm , no adjustments of editor needed.

    disclaimer
    It's a proof of concept hack!!!

    I'm not overly familiar with tty and forking and open for cleaner suggestions. :)

    Cheers Rolf

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

Re: Testing terminal programs within emacs (or other IDEs)
by wrog (Friar) on Nov 29, 2014 at 06:44 UTC
    run your program from M-x shell ?
      Thanks, but what's the advantage over "M-x term" ?

      Both solutions lack the possibility to activate the error lines like compile-mode does and other features...

      Cheers Rolf

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

        emacs related

        > Both solutions lack the possibility to activate the error lines like compile-mode does and other features...

        well this can be somehow solved by calling M-x compilation-minor-mode afetr the terminal has exited.

        Unfortunately I can't find a hook in term-mode to activate this minor-mode automatically after the terminal has exited.

        general question

        But this evolves too much around emacs now ... I think I should have asked the question differently emphasizing on filehandles and terminals to not only attract emacs folks:

        How do I run a perl application with TWO attached terminals, such that only STDERR goes to the second one?

        Cheers Rolf

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2026-03-08 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.