[slime-devel] Re: Handling ^M and ^H characters output from ext:run-program?

Mark Triggs mark at dishevelled.net
Sun Jul 17 01:22:27 UTC 2005

Hi Jeff,

Jeff Cunningham <jeffrey at cunningham.net> writes:

> It is a list. The command runs fine, its just filtering its output
> which is problematic. Here's the only thing I've been able to make
> work even remotely the way I want it to:
> (let ((rip (ext:process-output
>             (ext:run-program "cdrdao"
>                              '("read-test" "-v" "1" "--device" "0,6,0" "p7.toc")
>                              :output :stream
>                              :wait nil
>                              :error t))))
>   (do ((line (read-line rip nil 'done)
>              (read-line rip nil 'done)))
>       ((eql line 'eof))
>     (let ((progress (scan-to-strings "^Read \\d+ of \\d+ MB." line)))
>       (if progress
>           (format t "~a~%" progress)
>           (format t "~a~%" (subseq line 0 (1- (length line))))))))
> This works - except that there's no graceful exit out of the do loop - it results in the following:


> Read 0 of 547 MB.
> Read 36 of 547 MB.
> Read 104 of 547 MB.
> Read 264 of 547 MB.
> Read 341 of 547 MB.
> Read 418 of 547 MB.
> Read 244218 blocks.
> ; Compilation unit aborted.
> (After I kill the process in the *slime-repl*):

My version of cdrdao seems to write its output to stderr, not stdout, so
the above output is probably coming from your ":error t" argument.  I'm
not completely sure what you want to do, but this sort of approach seems
to work for me:

  (with-open-stream (rip (ext:process-error
                          (ext:run-program "cdrdao"
                                           '("read-test" "-v" "1" "test-toc.toc")
                                           :output nil
                                           :wait nil
                                           :error :stream)))
    (loop as line = (read-line rip nil)
       while line do
       (dolist (output-line (split (string #\Return) line))
         (when (cl-ppcre:scan "^Read \\d+ of \\d+ MB." output-line)
           (write-line output-line)))))



Mark Triggs
<mark at dishevelled.net>

More information about the slime-devel mailing list