🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #607

Re: Pipes, Child Processes and Other Uglies

#607
From: Drew Davidson
Date: Wed, 08 Apr 1992 15:16
55 lines
3124 bytes
In article <1992Apr7.170318.19742@noose.ecn.purdue.edu>  
songer@ei.ecn.purdue.edu (Christopher M Songer) writes:
> Hi!
>      It's possible this belongs on one of the UNIX groups, but it
> touches on some NeXT stuff so I thought I'd try here first. I'm in
> the midst of doing an App that uses Allegro for some NLP stuff. I'm
> spawning a cl process and making its stdin one end of a pipe, and its
> stdout another end of a pipe like this:
> 
> if((pid = fork()) == 0) {
> 	fclose(stdin);
> 	dup(cl_stdin);
> 	fclose(stdout);
> 	dup(cl_stdout);
> 	execl(...);
> 	}
> 
>      Here's my problem. Common Lisp can respond to commands in its
> own sweet time. I don't want to sit around polling on the file
> descriptor all the time. This would hose the user interface. What
> I want to happen is this:
> 
>      When the OS detects something to be read on the descriptor it
> wakes up a thread (or whatever) and the thread takes care of all my I/O.
> I think maybe the SIGIO signal sort of does this -- but it seems awefully
> crufty to me. (Not thread based at all, and who wants to poll ALL the
> possible descriptors.)
> 
>      One thing I've considered is using a thread with a realtively
> low priority to watch the file descriptor and buffer what comes through.
> Once we have a complete response from Lisp, send a message (or put an
> event in the Event Queue???) to process it. But I'm not sure that it
> is safe to use an objc messge from a thread and I'm not sure how to
> put an event in the event queue. I don't really want to have to subclass
> Application if I can help it.
> 
>      Anyway, suggestions on how to handle this are more then apprecaited.
> Thanks!
> -Chris
> songer@ecn.purdue.edu
> chris%broadsword.UUCP@ecn.purdue.edu

A very good solution to this problem is contained in  
/NextDevelopers/Examples/Subprocess.  It does exactly what you want and uses  
DPSAddFD() to tie into the stdin/stdout of the subprocess.  I have modified  
this further to separate the stdout from stderr (the Subprocess object blends  
them together), allow pausing and resuming the process and some other neat-o's.

--
+--------------------------------+------------------------------------------+
|        Drew  Davidson          | "Whining is anger coming through a small |
|         Software Guy           |  opening."                               |
| First National Bank of Chicago |            - Stuart Smalley              |
|     drew@fnbc.com  (NeXTmail)  |              Caring Nurturer             |
+--------------------------------+------------------------------------------+
Technical Details
Message-ID: <1992Apr8.151618.10043@fnbc.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!micro-heart-of-gold.mit.edu!rutgers!psinntp!psinntp!juliet!news
References: <1992Apr7.170318.19742@noose.ecn.purdue.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!micro-heart-of-gold.mit.edu!rutgers!psinntp!psinntp!juliet!news
From: drew@fnbc.com (Drew Davidson)
Newsgroups: comp.sys.next.programmer
Subject: Re: Pipes, Child Processes and Other Uglies
Message-ID: <1992Apr8.151618.10043@fnbc.com>
Date: 8 Apr 92 15:16:18 GMT
References: <1992Apr7.170318.19742@noose.ecn.purdue.edu>
Sender: news@fnbc.com
Reply-To: drew@fnbc.com
Organization: First National Bank Of Chicago, Chicago IL, USA
Lines: 55