Article View: be.comp.programming
Article #16115Re: piping in c++ (Linux)
From: Wim Dumon
Date: Mon, 26 Jun 2000 00:00
Date: Mon, 26 Jun 2000 00:00
43 lines
2125 bytes
2125 bytes
Thunderbird wrote:
>
> Wim Dumon wrote:
> >
> > #include <stdio.h>
> > #include <stdiostream.h>
> >
> > int main()
> > {
> > FILE *foo = popen("/bin/grep zeepbel", "w");
> > ostdiostream grep(foo);
> > grep << "a b c 1 2 3" << endl;
> > grep << "Een geexplodeerde zeepbel" << endl;
> > grep << "hopsasa tralala" << endl;
> > }
> >
> > Ik ben wel niet zeker dat stdiostream een standaard class is. Werkt in
> > elk geval op gcc 2.95.2. In het andere geval kan je nog altijd de
> > standaard C calls gebruiken (fprintf())
> >
>
> Ok, bedankt, werkt perfect hier, maar nu vraag ik mij af hoe ik de output van
> de functie system() in die mail kan stoppen. grep<< system(commando-oproep)
> werkt niet.
> De regels die ik krijg via system ("grep stringske uit_deze_file") komen
> gewoon op mijn scherm, maar dus niet in mijn mail.
>
FILE *in = popen("grep stringske uit_deze_file", "r");
FILE *out = popen("mail -s \"hier is ie\" foo@bar.com", "w");
int i;
while((i = fgetc(in)) != EOF)
fputc(i, out);
pclose(in);
pclose(out);
En da's niet helemaal juist (ivm EOF checking, lees de manpage voor
details). In C++ zal je dit natuurlijk ook anders kunnen schrijven met
input iterators of iets in dien aard maar da's alweer bijna meer werk in
dit geval dan wat hierboven staat.
Groetjes,
Wim.
Technical Details
Message-ID:
<3957611A.D73B78CA@easics.be>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39571EF3.521B9432@pandora.be> <39573F15.68D19DC6@easics.be> <39575A47.859C4E1A@pandora.be>Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit X-Google-Thread: fcea4,d6eda102769bf952 X-Google-Attributes: gidfcea4,public From: Wim Dumon <wim@easics.be> Subject: Re: piping in c++ (Linux) Date: 2000/06/26 Message-ID: <3957611A.D73B78CA@easics.be> X-Deja-AN: 639119534 Content-Transfer-Encoding: 7bit References: <39571EF3.521B9432@pandora.be> <39573F15.68D19DC6@easics.be> <39575A47.859C4E1A@pandora.be> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@kpnqwest.net X-Trace: nreader1.kpnqwest.net 962027805 193.74.198.7 (Mon, 26 Jun 2000 15:56:45 MET DST) Organization: Easics nv, Leuven, Belgium, http://www.easics.com MIME-Version: 1.0 NNTP-Posting-Date: Mon, 26 Jun 2000 15:56:45 MET DST Newsgroups: be.comp.programming