>>>>> "rif" == rif  <[EMAIL PROTECTED]> writes:

  rif> I'm still having a lot of difficulty with run-program.  I'm
  rif> communicating with R (a language for statistics and graphics), but so
  rif> far, I can only get one-way communication running.

  rif> This works fine for sending stuff to R, but I don't know how to read
  rif> from it.  A post by Eric Marsden in a previous thread suggests that
  rif> when I set :pty to t, I want to set all three of :input, :output and
  rif> :error to t.  However, if I do this, then writing to (process-pty *r*)
  rif> no longer works --- my plotting commands don't cause plots to appear,
  rif> and sending a "quit()" down the pipe no longer makes R quit.

R uses readline, which does tricky things with the terminal, so you
would probably need to write something like expect to communicate with
it over a pty. The following code, which runs R without readline and
uses a CMUCL I/O timeout mechanism, seems to work ok.


(defun interactive-read-line (stream)
  (handler-case (read-line stream nil nil)
    (system:io-timeout () nil)))

(defun run ()
  (let* ((r (ext:run-program "R" '("--no-save" "--no-readline")
                             :pty t :input t :output t :error t
                             :wait nil))
         (pty (ext:process-pty r)))
    (setf (lisp::fd-stream-timeout pty) 1)
    (write-line "licence()" pty)
    (force-output pty)
    (loop :for line = (interactive-read-line pty)
          :while line
          :do (format t "R> ~A~%" line))
    (write-line "quit()" pty)
    (force-output pty)
    r))

-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>

Reply via email to