[Openmcl-devel] access Mac OS python interpreter from clozure?

Dave Cooper david.cooper at genworks.com
Wed Oct 1 22:50:08 PDT 2014


If you want to do this portably, have a look at uiop:run-program. UIOP is a
CL portability package which comes with ASDF (but can also be loaded
separately). Of course it just calls through to CCL's run-program, and it
should support all the keyword arguments you need (although they may be a
little different in the portable UIOP version than in the CCL version -
that's a one-time mapping you would have to figure out).  The developer of
UIOP was very interested in making uiop:run-program into a robust
dependable defacto standard way to spawn external programs from Common
Lisp.




On Thu, Oct 2, 2014 at 1:27 AM, Gary Byers <gb at clozure.com> wrote:

>
>
> On 10/01/2014 05:15:02 PM, Mark Klein wrote:
>
>>
>> To add more detail to my previous question, I wonder if I can do
>> something like the following:
>>
>> (defun test ()
>>   (setq p (run-program "python" nil
>>                        :wait t
>>
>
> In general, if you want to "interact" with the external-proceess (rather
> than wait for it to complete) it's preferable to say :WAIT NIL here.  (You
> likely got past this point, if you discovered that reading the process's
> output likely hangs.)
>
>                         :input :stream
>>                        :output :stream))
>>   (setq is (external-process-input-stream p))
>>   (setq os (external-process-output-stream p))
>>   (loop do (format is "~A~%"  (read-line))
>>            do (format t "~%~A" (read-line os))))
>>
>> The idea is that this would create a process running python and allow me
>> to send and receive text to it. The code above doesn’t work, the read from
>> the external process output stream never returns, but perhaps there’s a
>> simple fix?
>>
>
> As Jeff Caldwell suggested, the output that the Python interpreter
> generates seems to be buffered on the Python side.  Starting Python with
> the "-i" option seens to defeat this buffering but also seems to cause it
> to print ">>>" prompts which aren't terminated by newlines after any other
> generated output.  (I guess that it can also generate "..."
> prompts in some cases.)  Reading the output generated by another process
> may be somewhat harder than just calling READ-LINE, and AFAICT Python's
> "-i" option can make it complicated in cases where it otherwise wouldn't be.
>
>
>>     Thanks,
>>
>> Mark
>>
>>
>> Hi,
>>
>> I’d like to create input and output streams that connect with the python
>> interpreter that comes included with Mac OS X so I can invoke python
>> subroutines from lisp and get the results. Does anyone have any suggestions
>> about how that can be done? I see that Clozure allows running other
>> programs as subprocesses (http://ccl.clozure.com/ccl-
>> documentation.html#Running-Other-Programs-as-Subprocesses) but it’s not
>> clear to me if I can use that to interact with a program like python, as
>> oppose to simply invoking a program like “cat” and getting the results it
>> returns when it completes.
>>
>> Thanks for your help!
>>
>> Mark
>>
>> -------------------------------
>> Mark Klein
>> http://cci.mit.edu/klein
>>
>> Principal Research Scientist
>> Center for Collective Intelligence
>> Massachusetts Institute of Technology
>>
>> Visiting Researcher
>> Dynamic and Distributed Information Systems Group
>> University of Zurich
>>
>>
>> -------------------------------
>> Mark Klein
>> http://cci.mit.edu/klein
>>
>> Principal Research Scientist
>> Center for Collective Intelligence
>> Massachusetts Institute of Technology
>>
>> Visiting Researcher
>> Dynamic and Distributed Information Systems Group
>> University of Zurich
>>
>>
>>
> ------quoted attachment------
>
>  _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://lists.clozure.com/mailman/listinfo/openmcl-devel
>>
>>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://lists.clozure.com/mailman/listinfo/openmcl-devel
>



-- 
My Best,

Dave Cooper, Genworks Support
david.cooper at genworks.com, dave.genworks.com(skype)
USA: 248-327-3253(o), 1-248-330-2979(mobile)
UK: 0191 645 1699
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20141002/d07f7c6b/attachment.htm>


More information about the Openmcl-devel mailing list