From: Jeff Cunningham
Subject: How do I handle ^M and ^H characters output from external programs?
Date: 
Message-ID: <pan.2005.07.13.02.21.59.891228@cunningham.net>
Hi,
                                                                                          
I have this code embedded in a process I'm running:
                                                                                          
(ext:process-exit-code
    (ext:run-program "cdrecord" args
        :output *standard-output*)))
                                                                                          
and it works fine, except that the cdrecord utility (and many others) uses
both backspace ^H and carriage return ^M to write updates to the screen.
This makes a big mess in the slime-repl window ,as they aren't properly
interpreted and so stuff spews out for miles before it finishes.
                                                                                          
Is there a way to capture these characters before they hit
*standard-output* and interpete them so they either work correctly or are
at least benign (i.e. convert carriage return to a linefeed, and any
sequence of backspaces ^H^H^H^H^H^H^H with a linefeed)?
                                                                                          
Regards,
                                                                                          
-Jeff Cunningham

From: Jeff Cunningham
Subject: Re: How do I handle ^M and ^H characters output from external programs?
Date: 
Message-ID: <pan.2005.07.15.02.26.31.516728@cunningham.net>
On Tue, 12 Jul 2005 19:22:01 -0700, Jeff Cunningham wrote:
(Bump)
No one has any ideas?



> Hi,
>                                                                                           
> I have this code embedded in a process I'm running:
>                                                                                           
> (ext:process-exit-code
>     (ext:run-program "cdrecord" args
>         :output *standard-output*)))
>                                                                                           
> and it works fine, except that the cdrecord utility (and many others) uses
> both backspace ^H and carriage return ^M to write updates to the screen.
> This makes a big mess in the slime-repl window ,as they aren't properly
> interpreted and so stuff spews out for miles before it finishes.
>                                                                                           
> Is there a way to capture these characters before they hit
> *standard-output* and interpete them so they either work correctly or are
> at least benign (i.e. convert carriage return to a linefeed, and any
> sequence of backspaces ^H^H^H^H^H^H^H with a linefeed)?
>                                                                                           
> Regards,
>                                                                                           
> -Jeff Cunningham
From: Christopher C. Stacy
Subject: Re: How do I handle ^M and ^H characters output from external programs?
Date: 
Message-ID: <uy888h94d.fsf@news.dtpq.com>
Jeff Cunningham <·······@cunningham.net> writes:

> On Tue, 12 Jul 2005 19:22:01 -0700, Jeff Cunningham wrote:
> > I have this code embedded in a process I'm running:
> >                                                                                           
> > (ext:process-exit-code
> >     (ext:run-program "cdrecord" args
> >         :output *standard-output*)))
> >                                                                                           
> > and it works fine, except that the cdrecord utility (and many others) uses
> > both backspace ^H and carriage return ^M to write updates to the screen.
> > This makes a big mess in the slime-repl window ,as they aren't properly
> > interpreted and so stuff spews out for miles before it finishes.
> >                                                                                           
> > Is there a way to capture these characters before they hit
> > *standard-output* and interpete them so they either work correctly or are
> > at least benign (i.e. convert carriage return to a linefeed, and any
> > sequence of backspaces ^H^H^H^H^H^H^H with a linefeed)?

This program that you're trying to run, "cdrecord", apparently 
is not designed to have its output piped into some other program.
It expects to be talking to your terminal.
This is not really a Lisp issue.

*STANDARD-OUTPUT* is bound to some Lisp stream maintained by SLIME,
attached to an Emacs buffer.   cdrecord was not designed to attach
to an Emacs buffer, or to anything other than a terminal (or some
program which emulates a terminal by understandin the control codes
for moving your cursor around).

You could use Simple Streams to write your own stream class which
understands those codes somehow (perhaps just turning them into
newlines or something).  Where the data eventually goes is up
to you, but your stream could encapsulate *STANDARD-OUTPUT*,
acting as a filter. Then you could call RUN-PROGRAM with an
instance of your stream, rather than *STANDARD-OUTPUT*.
From: Jeff Cunningham
Subject: Re: How do I handle ^M and ^H characters output from external programs?
Date: 
Message-ID: <pan.2005.07.15.11.26.41.107482@cunningham.net>
On Fri, 15 Jul 2005 06:32:51 +0000, Christopher C. Stacy wrote:


> This program that you're trying to run, "cdrecord", apparently 
> is not designed to have its output piped into some other program.
> It expects to be talking to your terminal.
> This is not really a Lisp issue.
> 
> *STANDARD-OUTPUT* is bound to some Lisp stream maintained by SLIME,
> attached to an Emacs buffer.   cdrecord was not designed to attach
> to an Emacs buffer, or to anything other than a terminal (or some
> program which emulates a terminal by understandin the control codes
> for moving your cursor around).
> 
> You could use Simple Streams to write your own stream class which
> understands those codes somehow (perhaps just turning them into
> newlines or something).  Where the data eventually goes is up
> to you, but your stream could encapsulate *STANDARD-OUTPUT*,
> acting as a filter. Then you could call RUN-PROGRAM with an
> instance of your stream, rather than *STANDARD-OUTPUT*.

That makes sense. I'll work on it from that angle.
Thanks.

--Jeff Cunningham
From: Pascal Bourguignon
Subject: Re: How do I handle ^M and ^H characters output from external programs?
Date: 
Message-ID: <87eka0fi3d.fsf@thalassa.informatimago.com>
Jeff Cunningham <·······@cunningham.net> writes:

> On Tue, 12 Jul 2005 19:22:01 -0700, Jeff Cunningham wrote:
> (Bump)
> No one has any ideas?

With inferior-lisp instead of slime,
(format t "Hello~C~C~Crmosa~%" #\backspace  #\backspace  #\backspace )
eventually shows as:
Hermosa

Try to run your program inferior-lisp instead of slime.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The mighty hunter
Returns with gifts of plump birds,
Your foot just squashed one.