Date: Sun, 27 Dec 1998 21:09:44 -0500 (EST) From: Chuck Robey <chuckr@mat.net> To: Yani Brankov <ian@bulinfo.net> Cc: hackers@FreeBSD.ORG Subject: Re: howto redirect stdin/stdout Message-ID: <Pine.BSF.4.05.9812272104410.335-100000@picnic.mat.net> In-Reply-To: <3686C942.B51A4937@bulinfo.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 28 Dec 1998, Yani Brankov wrote: > > Hi, > > Maybe it's a stupid question, but I don't have much time to search into > the FreeBSD sources for an example. > > I need to redirect the stdout from a parent process > to stdin to its child within a C program. > > Imagine I would like to start lpr(1) with exec(3) from the C program > and send data to stdin of the lpr(1) from the same C prg. > > I don't know what to do with the file descriptors. > > If you don't have much time too, just tell me where to find a helpful > example. Two answers. This is either a very simple thing, or a mildly complicated one (depending on your C sophistication). The simplest way is to use popen, look at the man page, it's not real hard, and the pipe comes automatically made correctly for you. The other method, which I *really* recommend anyways, is to go out and buy Richard Stevens book Advanced Programming In The Unix Environment. I know book money comes dear, but this book is a keeper, and explains all the contortions you could possibly want to know, making a program interact with the Unix OS. Extremely recommended by anyone who's ever read it, really. This will show you how to use popen, and also how to go ahead and make your own parent<->child connection the way you (roughly) described. > > Thanks in advance. > > --ian > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > > ----------------------------+----------------------------------------------- Chuck Robey | Interests include any kind of voice or data chuckr@glue.umd.edu | communications topic, C programming, and Unix. 213 Lakeside Drive Apt T-1 | Greenbelt, MD 20770 | I run Journey2 and picnic (FreeBSD-current) (301) 220-2114 | and jaunt (NetBSD). ----------------------------+----------------------------------------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9812272104410.335-100000>