From: jcb
Subject: ACL on OS X:launching mlisp and communication via NSTask
Date: 
Message-ID: <2007020314571316807-nomail@nononoorg>
Hi all this is a specific question about ACL on OS X:

I am launching mlisp from a Cocoa application using NSTask. The code 
looks like this:


NSTask *lisp = [[NSTask alloc] init];

// Set path to executable	
[lisp ··············@"/Applications/acl80/mlisp"];

// Run mlisp as a process
[lisp launch];


Pretty simple. This launches ACL and I see the startup banner in the 
run log window. I can even interact with it.  Neat! But I'm not having 
any luck communicating with the process programmatically.

A launched NSTask inherits the stdin and stdout of the parent process 
(unless you give it different file handles, which I am not doing -- my 
launched NSTask inherits stdin and stdout from the Cocoa application). 
I have some code to write to stdin:


const char *s = "(+ 2 2)";
	
if([lisp isRunning]) {
		
  // Get the stdin file handle of the process and write the expression.
  [[lisp standardInput] writeData:[NSData dataWithBytes:s length:strlen(s)]];
		
}

This basically does nothing. I see the string (+ 2 2) appear in the run 
log window, but ACL does not evaluate it or respond in any way.

What obvious thing am I missing..?? I tried terminating the string with 
\n, 0x04 (ctrl+d), and various combinations...no luck. 
Thoughts....discuss..... ?

Thanks,
JCB

From: Ken McKee
Subject: Re: ACL on OS X:launching mlisp and communication via NSTask
Date: 
Message-ID: <1170576614.794640.323440@m58g2000cwm.googlegroups.com>
jcb wrote:
> Hi all this is a specific question about ACL on OS X:
>
> I am launching mlisp from a Cocoa application using NSTask. The code
> looks like this:
>
>
> NSTask *lisp = [[NSTask alloc] init];
>
> // Set path to executable
> [lisp ··············@"/Applications/acl80/mlisp"];
>
> // Run mlisp as a process
> [lisp launch];
>
>
> Pretty simple. This launches ACL and I see the startup banner in the
> run log window. I can even interact with it.  Neat! But I'm not having
> any luck communicating with the process programmatically.
>
> A launched NSTask inherits the stdin and stdout of the parent process
> (unless you give it different file handles, which I am not doing -- my
> launched NSTask inherits stdin and stdout from the Cocoa application).
> I have some code to write to stdin:
>
>
> const char *s = "(+ 2 2)";
>
> if([lisp isRunning]) {
>
>   // Get the stdin file handle of the process and write the expression.
>   [[lisp standardInput] writeData:[NSData dataWithBytes:s length:strlen(s)]];
>
> }
>
> This basically does nothing. I see the string (+ 2 2) appear in the run
> log window, but ACL does not evaluate it or respond in any way.
>
> What obvious thing am I missing..?? I tried terminating the string with
> \n, 0x04 (ctrl+d), and various combinations...no luck.
> Thoughts....discuss..... ?
>
> Thanks,
> JCB

I've never seen it done that way.
Most every example I've seen of NSTask uses NSPipes for communication.

http://macosx.com/forums/software-programming-web-scripting/4522-better-way-read-nstask.html

http://www.macusersforum.com/lofiversion/index.php?t8251.html

http://www.mactech.com/articles/mactech/Vol.20/20.05/ShellGameII/index.html

It is also possible to load the acl dylib and call lisp directly. I
don't have the details in front of me, but I can find them if you are
interested.

-Ken
From: jcb
Subject: Re: ACL on OS X:launching mlisp and communication via NSTask
Date: 
Message-ID: <2007020408141675249-nomail@nononoorg>
On 2007-02-04 00:10:14 -0800, "Ken McKee" <·······@bmrc.mc.duke.edu> said:

> 
> jcb wrote:
>> Hi all this is a specific question about ACL on OS X:
>> 
>> I am launching mlisp from a Cocoa application using NSTask. The code
>> looks like this:
>> 
>> 
>> NSTask *lisp = [[NSTask alloc] init];
>> 
>> // Set path to executable
>> [lisp ··············@"/Applications/acl80/mlisp"];
>> 
>> // Run mlisp as a process
>> [lisp launch];
>> 
>> 
>> Pretty simple. This launches ACL and I see the startup banner in the
>> run log window. I can even interact with it.  Neat! But I'm not having
>> any luck communicating with the process programmatically.
>> 
>> A launched NSTask inherits the stdin and stdout of the parent process
>> (unless you give it different file handles, which I am not doing -- my
>> launched NSTask inherits stdin and stdout from the Cocoa application).
>> I have some code to write to stdin:
>> 
>> 
>> const char *s = "(+ 2 2)";
>> 
>> if([lisp isRunning]) {
>> 
>> // Get the stdin file handle of the process and write the expression.
>> [[lisp standardInput] writeData:[NSData dataWithBytes:s length:strlen(s)]];
>> 
>> }
>> 
>> This basically does nothing. I see the string (+ 2 2) appear in the run
>> log window, but ACL does not evaluate it or respond in any way.
>> 
>> What obvious thing am I missing..?? I tried terminating the string with
>> \n, 0x04 (ctrl+d), and various combinations...no luck.
>> Thoughts....discuss..... ?
>> 
> 
> I've never seen it done that way.
> Most every example I've seen of NSTask uses NSPipes for communication.

Hi Ken - I do have a couple of examples of using pipes. Thanks for the 
extra ones in the links.

I will switch to pipes and see what happens...it *seems* though (at 
least to me :-) ) - that using stdin and stdio file handles already in 
the NSTask after launching should work.

When I run from Xcode, I can see my expression appear in the standard 
I/O window when I write it to the stdin file handle. It's almost as 
though ACL is waiting for a character to trigger an evaluation but like 
I said none of the usual suspects work. OTOH maybe I'm not seeing what 
I think I'm seeing in the I/O window of Xcode.


> 
> 
> It is also possible to load the acl dylib and call lisp directly. I
> don't have the details in front of me, but I can find them if you are
> interested.


Hmmmm....that's a thought -- I'll look into that. I'm sure I can find a 
starting place  in the ACL docs.

Thanks again,
John