Is popen() the only way to read data from (or two) a executable program
in C++?
Thanks, in advance.
Mojo
> Is popen() the only way to read data from (or two) a executable program
> in C++?
>
Probably. Since ANSI/ISO C or C++ does not even define such a
function, there would be no "standard" way of accomplishing what popen
does. POSIX.2 does define a popen(3), and should appear on any POSIX
compliant OS.
Since most UNIX function calls are in C, a C++ version using an
streams is probably not available, or at least not available on a wide
number of platforms.
One possibility, which may or may not work is to use popen to produce
the FILE *, use fileno to retrieve the file descripter and use fstream
the file descriptor. Of course there is a chance that this will work,
but I wouldn't bet the farm on it.
--
Dan Nguyen | It is with true love as it is with ghosts;
nguy...@msu.edu | everyone talks of it, but few have seen it.
d...@debian.org | -Maxime De La Rochefoucauld
I'd give it a high probability of working. What's likely to prevent it?
I've long wondered why C++ doesn't have a standard way of creating a C++
iostream from a C FILE*. It provides lots of other features for C/C++
interoperability, so this seems like a natural thing to do.
--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
I was trying to get fstream to work on FILE *, without using fileno, so
thanks for that as well.
It did work, and a much nicer solution then going back and rewriting the
whole program.
Thanks
Mojo
Dan Nguyen wrote:
> "Mojo B. Nichols" <dkl...@flash.net> writes:
>
> > Is popen() the only way to read data from (or two) a executable program
> > in C++?
> >
>
> Probably. Since ANSI/ISO C or C++ does not even define such a
> function, there would be no "standard" way of accomplishing what popen
> does. POSIX.2 does define a popen(3), and should appear on any POSIX
> compliant OS.
>
> Since most UNIX function calls are in C, a C++ version using an
> streams is probably not available, or at least not available on a wide
> number of platforms.
>
> One possibility, which may or may not work is to use popen to produce
> the FILE *, use fileno to retrieve the file descripter and use fstream
> the file descriptor. Of course there is a chance that this will work,
> but I wouldn't bet the farm on it.
>