File descriptors

Discussion of Common Lisp

File descriptors

Postby aidlt » Sun Jun 02, 2013 1:13 pm

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 is in Python 2 and looks like this:
Code: Select all
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)
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.
Posts: 19
Joined: Thu May 16, 2013 1:42 pm

Re: File descriptors

Postby nuntius » Sun Jun 02, 2013 8:25 pm

Unfortunately, there's no standard way to do this; each implementation has its own hooks.

You could borrow from LTK's code. Go to and search for do-execute.

Here are some libraries that may help.
inferior-shell ... -shell.git
User avatar
Posts: 532
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: File descriptors

Postby aidlt » Mon Jun 03, 2013 1:50 pm

Thanks, nuntius! I'll check all of those out.
Posts: 19
Joined: Thu May 16, 2013 1:42 pm

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 5 guests