"scarbonell@..." <scarbonell@...> writes:
> Hi,
>
> I'm trying to redirect lisp stardard-output to sockets and with the
> algorith from Pascal, works fine, but now I have got another problem
> is that stardard-input is not appearing in the java console.
>
> In lisp there are this function:
>
> (let* ((*standard-input* socket)
> (*standard-output* socket)
> (*error-output* socket)
> (*trace-output* socket)
> (*terminal-io* (make-two-way-stream *standard-input* *standard-output*))
> (*query-io* *terminal-io*)
> (*debug-io* *terminal-io*)
> ;; We make a closure to capture socket here:
> (force-output (lambda () (force-output socket))))
> (handler-case
> (let ((socket nil) ; so that we can shadow it here.
> (results (multiple-value-list (eval (read)))))
> (funcall force-output)
> (format t "~&--> ~{~S~^~% ~}~%" results)
> (format t "--FIN--")
> (funcall force-output))
> (error (err)
> (funcall force-output)
> (format t "~&ERROR: ~A~%" err)
> (funcall force-output))))
>
> and works fine to redirect standard-output to socket. It's suppose
> that standard-input is redirected to the same socket too, and in the
> lisp code, there are other function to obtain the input information
> using read-char, but ignores it.
>
> (def$method (tty-dialog-mixin :confirm) (&rest comments)
> "writes comments to dialog-stream and waits for input.
> comments are printed without slashification.
> returns :yes if *end-key* is entered and nil otherwise."
> (lexpr-$send self :notify comments)
> (format dialog-stream "~:[~;~%~] ~@? "
> (rest comments)
> (getentry type-end-to-confirm-str babylon-io-table)
> *end-key*)
> (force-output dialog-stream)
> (let ((char (read-char dialog-stream)))
> (if (eql char *end-key*)
> :yes)))
>
> I've changed dialog-stream by *standard-input*, but I obtain the same result:
>
> I enter some key but appears "EVAL: variable E has no value", it's
> like that the function in the lisp code doesn't capture the key, so
> the function doesn't work and the program is stopped. I don't know how
> to stop the execution when in lisp code appears the read-char function
> and to wait I enter some value.
When READ-CHAR is called (also thru READ, READ-LINE, etc), the clisp
process calls read(2) on the socket. If there are no bytes received,
then the operating system waits, blocking the clisp process, until some
byte is received on that socket.
So what are you doing on the other side, in the Java process? Why
aren't you sending some bytes? Also, if you use read-line, be sure to
send a newline, and if you expect an *end-key*, be sure to send it (and
flush it) from the java side.
Now there would be other, more complex ways to do it. Using
gray-streams, you could implement a method to read characters or lines
that would send a message to the java side, upon receiption of which the
java side would read a character or line from the user and send it back,
and then your gray-stream would return it as read. Thus you would have
to implement a specific protocol, an "input" server on the java side,
and a gray-stream subclass in clisp. Much more complex. But this would
allow for example to pop-up dialogs on the java side when input is
required. Also, you could deal with the *query-io* specially, gathering
all output on *query-io* to be displayed on the dialog popped-up when
reading from *query-io* and other fancy things.
But if you don't want to enter in those complexities, then just ensure
that the java side is both reading from the socket to get output from
lisp, AND writing to the socket any inut the lisp side must read.
Typically, you could have in java something like:
(loop
(when (listen *terminal-io*)
(write-line (read-line *terminal-io*) clisp-socket))
(when (listen clisp-socket)
(write-line (read-line clisp-socket) *terminal-io*)))
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
|