Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #13117 > unrolled thread

open stdin a second time

Started byFBert <anon@devnull.invalid>
First post2011-11-11 20:11 +0000
Last post2011-11-11 20:12 -0500
Articles 3 — 3 participants

Back to article view | Back to comp.lang.c


Contents

  open stdin a second time FBert <anon@devnull.invalid> - 2011-11-11 20:11 +0000
    Re: open stdin a second time James Kuyper <jameskuyper@verizon.net> - 2011-11-11 15:31 -0500
    Re: open stdin a second time Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-11 20:12 -0500

#13117 — open stdin a second time

FromFBert <anon@devnull.invalid>
Date2011-11-11 20:11 +0000
Subjectopen stdin a second time
Message-ID<j9jvia$gsb$1@speranza.aioe.org>
Hi,

I´m opening stdin to get a file and pass it through a pipe.

razor=popen("/var/qmail/bin/razor-check -home=/var/qmail/razor",
"w");
while((ret=fread(linha,1,sizeof(linha),stdin))>0)
{fwrite(linha,1,sizeof(linha),razor);}
pclose(razor);

After that, if razor returns me an error I want to send an email with
the original message attached...but how can I re-read stdin to do
that.

I do not want to save the message to a temp file or save it to memory
for i/o questions. Is there a way to re-read stdin ? 

[toc] | [next] | [standalone]


#13119

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-11-11 15:31 -0500
Message-ID<4EBD8615.2040607@verizon.net>
In reply to#13117
On 11/11/2011 03:11 PM, FBert wrote:
> Hi,
> 
> I´m opening stdin to get a file and pass it through a pipe.
> 
> razor=popen("/var/qmail/bin/razor-check -home=/var/qmail/razor",
> "w");
> while((ret=fread(linha,1,sizeof(linha),stdin))>0)
> {fwrite(linha,1,sizeof(linha),razor);}
> pclose(razor);
> 
> After that, if razor returns me an error I want to send an email with
> the original message attached...but how can I re-read stdin to do
> that.
> 
> I do not want to save the message to a temp file or save it to memory
> for i/o questions. Is there a way to re-read stdin ? 

That depends upon what kind stream stdin is. The message has to be
stored somewhere if you're to retrieve it. If stdin is a terminal, for
instance, if you don't save the message yourself, then it isn't saved
anywhere, and you're out of luck.

On the other hand, if stdin is a file, the information is saved - in
that file. You can use rewind() to go back to the beginning of the file,
or either fseek() or fsetpos() to go back to specific saved positions in
the file.

[toc] | [prev] | [next] | [standalone]


#13157

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-11-11 20:12 -0500
Message-ID<j9kh6g$v7m$1@dont-email.me>
In reply to#13117
On 11/11/2011 3:11 PM, FBert wrote:
> Hi,
>
> I´m opening stdin to get a file and pass it through a pipe.
>
> razor=popen("/var/qmail/bin/razor-check -home=/var/qmail/razor",
> "w");
> while((ret=fread(linha,1,sizeof(linha),stdin))>0)
> {fwrite(linha,1,sizeof(linha),razor);}
> pclose(razor);
>[...]

     See James Kuyper's response.  In addition, note that the third
argument to fwrite() should almost certainly be `ret', because there's
an excellent chance that the tail end of `linha' will be whatever was
left over from the next-to-last input line.  (For extra credit, examine
the value returned by fwrite() to see whether it actually worked.)

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web