This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

File descriptors

3 posts · 3043 views

I'm trying to make a Common Lisp front end to the Asymptote vector graphics language. I'd like to establish communication between a Lisp process and an Asymptote process and I have problems with this. Somehow Asymptote is hard to communicate with. The only working piece of code I have (stripped from xasy2asy.py) is in Python 2 and looks like this:
import os
from subprocess import *
(rx, wx) = os.pipe()
(ra, wa) = os.pipe()
asy = Popen(['asy', '-noV', '-multline', '-q', '-inpipe=' + str(rx), '-outpipe=' + str(wa)])
fout = os.fdopen(wx, 'w')
fin = os.fdopen(ra, 'r')
fout.write("file fout = output(mode = 'pipe');\n")
fout.write("write(fout, sin(1), endl);\n") # just an example: calculate sin(1)
fout.flush()
print fin.readline() # this works, indeed!
In short, Python launches Asymptote with (undocumented!) options -inpipe and -outpipe taking file descriptors and uses corresponding file objects for communication.

I'd love to implement this in Lisp (since I don't see another way of doing that). However, there's much to be desired about my real-life Lisp skills, and what's more I'm not much skilled in inter-process communication. I've been reading a lot these days, and I've got a mess of descriptors, sockets, and suchlike in my head. :( I'd be happy if you at least point me in the right direction: usocket, iolib, implementation dependent tools...

As for the result, of course I'd like it to be portable. Or at least SBCL and CLISP. Or at least SBCL. :)

Any help appreciated.

Re: File descriptors

Thanks, nuntius! I'll check all of those out.