Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

popen

0 views
Skip to first unread message

Mojo B. Nichols

unread,
Oct 11, 2000, 3:00:00 AM10/11/00
to

Is popen() the only way to read data from (or two) a executable program
in C++?


Thanks, in advance.


Mojo

Dan Nguyen

unread,
Oct 11, 2000, 3:00:00 AM10/11/00
to
"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.

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

Barry Margolin

unread,
Oct 11, 2000, 3:00:00 AM10/11/00
to
In article <fxsr95n...@arctic.cse.msu.edu>,

Dan Nguyen <nguy...@msu.edu> wrote:
>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.

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.

Mojo B. Nichols

unread,
Oct 11, 2000, 3:00:00 AM10/11/00
to
Hey, thanks.

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

0 new messages