Article View: comp.sys.amiga.tech
Article #9584Re: Is there a preferred way to do popen()?
From: Bill Hawes
Date: Tue, 23 Aug 1988 22:52
Date: Tue, 23 Aug 1988 22:52
36 lines
2061 bytes
2061 bytes
With regard to pipe devices and a popen() function on the Amiga:
There's an extremely easy way to implement a popen() function, using the
PIP: handler built into ConMan. What, you didn't know ConMan was a pipe
handler, as well as a CON:, CNC:, RAW:, and soon others? Well, you never
asked ...
To implement a popen(), just do the following:
(1) Allocate a FileHandle structure, using the usual DOS memory convention
(2) Call Open("PIP:",2000L) to get one filehandle
(3) Copy the filehandle from the Open() to the one you allocated, keeping
all the usual things in mind (BPTRs, you know)
The two filehandles can now be returned to the user, and should eventually
be Close()d when you're done. AmigaDOS filehandles work for both reading
and writing.
The PIP: handler must be mounted before using (with the mountlist entry
included with ConMan). The default pipe size is 4000 bytes, and can be
sized by specifying a byte count when you open it (e.b. PIP:10000).
One more trick/trap: the AmigaDOS Close() function automatically flushes
BCPL buffers if the filehandle wasn't opened as MODE_NEWFILE, as the pipe
filehandle wasn't. Therefre, if you've used the pipe with BCPL programs
(unlikely unless you're a command shell), you have to make sure the
filehandle buffer looks empty before closing it, or you'll get a deadlock
if the pipe is blocked at the time. The buffer will look empty if you
set fh_Pos = 0 before closing.
Have fun, and let me know how it works out.
Bill Hawes (ConMan author)
Technical Details
Message-ID:
<1995@dino.ulowell.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!necntc!dandelion!ulowell!hawesReferences:
<618@super.ORG> <601@faui44.informatik.uni-erlangen.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!necntc!dandelion!ulowell!hawes From: hawes@dino.ulowell.edu (Bill Hawes) Newsgroups: comp.sys.amiga.tech Subject: Re: Is there a preferred way to do popen()? Message-ID: <1995@dino.ulowell.edu> Date: 23 Aug 88 22:52:35 GMT References: <618@super.ORG> <601@faui44.informatik.uni-erlangen.de> Reply-To: hawes@dino.ulowell.edu (Bill Hawes) Organization: University of Lowell Productivity Center, Lowell MA. Lines: 35