Page 1 of 1

File descriptors

Posted: Sun Jun 02, 2013 1:13 pm
by aidlt
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:

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)
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

Posted: Sun Jun 02, 2013 8:25 pm
by nuntius
Unfortunately, there's no standard way to do this; each implementation has its own hooks.

You could borrow from LTK's code. Go to http://ltk.rplay.net/svn/trunk/ltk/ltk.lisp and search for do-execute.

Here are some libraries that may help.
trivial-shell http://common-lisp.net/project/trivial-shell/
inferior-shell http://common-lisp.net/gitweb?p=project ... -shell.git
IOLib http://common-lisp.net/project/iolib/

Re: File descriptors

Posted: Mon Jun 03, 2013 1:50 pm
by aidlt
Thanks, nuntius! I'll check all of those out.