Manage pipe by stdio_filebuf

M

marco

===================================================
I've posted the same message to comp.lang.c++.moderated
===================================================
hi everybody
I've written a small program posted below in the message.
It should print the content of a generic file in a shell window by a
pipe.
I use a popen() function to create a pipe and stdio_filebuf to
interface it
with a ostrem object.
I compile the program with g++ 3.2.3 and I don't have any problem
about the compilation.
When I try to execute the program I receive a "segmentation fault".

The program works properly if I put the code relative to popen
function and the
stdio_filebuf object in the main. I don't understand which is the
problem.

Any idea?

Thanks

Marco

=======================================================
Code

#include <ext/stdio_filebuf.h>
#include <stdio.h>
#include <iostream>
#include <fstream>

typedef __gnu_cxx::stdio_filebuf<char> filebuf_gnu;


filebuf_gnu& open(char *command)
{


f=popen(command,"w");
filebuf_gnu tempw(f,std::ios_base::eek:ut,1024);
filebuf_gnu &pnt=tempw;

return (pnt);
}


int main()
{

filebuf_gnu &temp = (open("cat"));

std::eek:stream out(&temp);
std::ifstream file("../src/prova_marco.cxx");
if (!file) cout<<"errore apertura file";
out<<file.rdbuf();

return 0;
}

=============================================================
 
R

Rolf Magnus

marco said:
===================================================
I've posted the same message to comp.lang.c++.moderated
===================================================

.... and to gnu.gcc.help, where I answered it, as well as to
gnu.g++.help. When you think you need to post to multiple newsgroups,
please use cross-posting instead of multi-posting. That means that you
should send only one posting and specify all the groups that it should
go to instead of sending a separate posting to each of the newsgroup.
 
M

marco

Rolf Magnus said:
... and to gnu.gcc.help, where I answered it, as well as to
gnu.g++.help. When you think you need to post to multiple newsgroups,
please use cross-posting instead of multi-posting. That means that you
should send only one posting and specify all the groups that it should
go to instead of sending a separate posting to each of the newsgroup.

Ok, I'm sorry

Marco
 

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

Similar Threads

C pipe 1
Chatbot 0
exec and named pipe questions 11
Daemonization / Popen / pipe issue 0
Infinite loop problem 1
Crossword 2
Crossword 14
Open a command pipe for reading 2

Members online

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,440
Latest member
in3dagenonline

Latest Threads

Top