[comp.unix.wizards] How can I write an FPIPE

djm@dmntor.UUCP (David McKellar) (02/08/91)

Quick description:

	I know all about pipe() and popen() but I want a fpipe().
	AND I can't figure out how to do it!!!

More detailed:

	pipe() returns those int file descriptors so I can't
	use fprintf().  (sprintf() followed by write() is clumbsy!)

	popen() returns type FILE so I can use fprintf() but
	it calls sh so an extra process is used.

	What I want is an fpipe() that does exactly the same as pipe
	but returns type FILE.  Possible ?

Please e-mail me as well as posting.
-- 
Dave McKellar
UUCP: djm@dmntor.UUCP 
UUCP bang: ...!uunet!jtsv16!geac!dmntor!djm
BITNET: djm%dmntor.UUCP@UWOCC1 (I think)

fox@rudolf.nscl.msu.edu (Ron Fox) (02/08/91)

--
In article <1991Feb7.200302.4945@dmntor.UUCP>, djm@dmntor.UUCP (David
McKellar) writes:

>Quick description:
>
>	I know all about pipe() and popen() but I want a fpipe().
>	AND I can't figure out how to do it!!!
>
 
 You're going to feel a bit foolish... look at the routine fdopen()
(3s)
It opens a stream (FILE * type) given as input a file descriptor (what
pipe() returns).

		Ron

Ron Fox                     | FOX@MSUNSCL.BITNET      | Where the name 
NSCL                        | FOX@RUDOLF.NSCL.MSU.EDU | goes on before
Michigan State University   | MSUHEP::RUDOLF::FOX     | the quality
East Lansing, MI 48824-1321 |                         | goes in.
USA

rbj@uunet.UU.NET (Root Boy Jim) (02/09/91)

In <1991Feb7.200302.4945@dmntor.UUCP> djm@dmntor.UUCP (David McKellar) writes:
>	I know all about pipe() and popen() but I want a fpipe().

Take the FD's you get from pipe or popen and use fdopen on them.
-- 

	Root Boy Jim Cottrell <rbj@uunet.uu.net>
	I got a head full of ideas
	They're driving me insane

gwyn@smoke.brl.mil (Doug Gwyn) (02/09/91)

In article <1991Feb7.200302.4945@dmntor.UUCP> djm@dmntor.UUCP (David McKellar) writes:
>	What I want is an fpipe() that does exactly the same as pipe
>	but returns type FILE.  Possible ?

Any time you can get a file descriptor and want a FILE, use fdopen().

This question should have been posted to comp.unix.questions.

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (02/12/91)

As quoted from <1991Feb7.200302.4945@dmntor.UUCP> by djm@dmntor.UUCP (David McKellar):
+---------------
| 	pipe() returns those int file descriptors so I can't
| 	use fprintf().  (sprintf() followed by write() is clumbsy!)
+---------------

Try "man 3 fdopen" (Unix) or "man S fdopen" (SCO's abominations).

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY