[Openmcl-devel] External process i/o weirdness?

Gary Byers gb at clozure.com
Wed May 14 17:53:57 UTC 2003



On Wed, 14 May 2003, Gary Byers wrote:

>
>
> On Wed, 14 May 2003, Michael Klingbeil wrote:
>
> > I'm having some trouble sending data to an external process created
> > via ccl:run-program. If I understand the documentation correctly if I
> > pass :stream as the input option, then I should be able to write to a
> > stream which will serve as the input feeding the external process.
> >
> > However, whenever I try to write to this stream, I get errors. In
> > fact as I experiment further is sort of looks like the input and
> > output streams are double reversed -- the data structures for input
> > and output are reversed but the file descriptors are also reversed --
> > so nothing works! But there might be something I am totally missing.
> >
>
> One thing that's pretty scary in the output below is that a lot of
> the file descriptor-based streams are printing out as
>
>      #<FD-CHARACTER-INPUT-STREAM (NIL/4) #x566423E>
>                                   ^^^
> Instead of NIL/4, I'd kind of expect to see :PIPE/4, or :FILE/4; I think
> we're looking at streams whose FD has been closed (deliberately but
> mistakenly.)  The issue of which is input (to what) and which is output
> certainly matters, but it doesn't look like we could do any I/O to either
> of these streams even if that issue was clear.
>
> (In fact, if you write a string to the external-process-output-stream
> and then FORCE-OUTPUT on it, you'll get an error indicating that the
> file descriptor is "bad".  I assume that "bad" means "closed" in this
> case.)
>
> I'm not looking at the code at the moment, but I will try to send a
> patch as soon as this starts making sense ...
>

The fact that the streams were getting reversed sort of explains why
the FDs were getting closed.

This is happening in the function CCL::GET-DESCRIPTOR-FOR.  The
following patch should get the stream directions sorted out in that
case (and refrain from closing file descriptors that we want to use
on the lisp side.)

? (run-program "cat" () :input :stream :output :stream :wait nil)
#<EXTERNAL-PROCESS [7600] (RUNNING) #x3537D83E>
? (defvar *cat-process* *)
*CAT-PROCESS*
? (describe *cat-process*)
#<EXTERNAL-PROCESS [7600] (RUNNING) #x3537D83E>
Type: EXTERNAL-PROCESS
Class: #<STRUCTURE-CLASS EXTERNAL-PROCESS>
PID: 7600
%STATUS: :RUNNING
%EXIT-CODE: NIL
PTY: NIL
INPUT: #<FD-CHARACTER-OUTPUT-STREAM (PIPE/7) #x3537D666>
OUTPUT: #<FD-CHARACTER-INPUT-STREAM (PIPE/8) #x3537D746>
ERROR: #<FD-CHARACTER-INPUT-STREAM (PIPE/8) #x3537D746>
STATUS-HOOK: NIL
PLIST: NIL
TOKEN: (0)
CORE: NIL

? (let* ((input-to-cat-process (external-process-input-stream *cat-process*))
         (output-from-cat-process (external-process-output-stream *cat-process*)))
  (format input-to-cat-process "This is some input~&")
  (force-output input-to-cat-process)
  (read-line output-from-cat-process))
"This is some input"
NIL


Index: level-1/linux-files.lisp
===================================================================
RCS file: /usr/local/publiccvs/ccl/level-1/linux-files.lisp,v
retrieving revision 1.22
diff -u -r1.22 linux-files.lisp
--- level-1/linux-files.lisp	19 Jan 2003 08:08:07 -0000	1.22
+++ level-1/linux-files.lisp	14 May 2003 17:37:24 -0000
@@ -483,15 +483,15 @@
        (case direction
 	 (:input
 	  (values read-pipe
-		  (make-fd-stream read-pipe
-				  :direction :input
+		  (make-fd-stream write-pipe
+				  :direction :output
 				  :interactive nil)
 		  (cons read-pipe close-in-parent)
 		  (cons write-pipe close-on-error)))
 	 (:output
 	  (values write-pipe
-		  (make-fd-stream write-pipe
-				  :direction :output
+		  (make-fd-stream read-pipe
+				  :direction :input
 				  :interactive nil)
 		  (cons write-pipe close-in-parent)
 		  (cons read-pipe close-on-error)))

_______________________________________________
Openmcl-devel mailing list
Openmcl-devel at clozure.com
http://clozure.com/cgi-bin/mailman/listinfo/openmcl-devel



More information about the Openmcl-devel mailing list