open stdin a second time

F

FBert

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 ?
 
J

James Kuyper

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.
 
E

Eric Sosman

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top