tags:

views:

191

answers:

3

Is their any C popen() equivalent in C++ to ?

+5  A: 

C++ is a superset of C. popen is available to C++ code as well.

Borealid
I don't think that popen is required by the Standard.
DeadMG
Which standard? popen comes from POSIX.1-2001. Even Windows has a POSIX-compatibility layer. Linux and MacOS support it natively, of course. It's a library function, not part of the C standard itself.
Borealid
popen() is part of POSIX, so any UNIX-like operating system should support it. Even for non-POSIX OSes, if you have popen() in C, you should be able to use it in C++, unless there's something very wrong with your compiler.
Chris
Technically, C++ isn't a superset of C.
You
I know popen is available in c++. But I am flexible C++ iostream.
Arif
@You: Saying C++ isn't a superset of C is like saying Python 3.0 isn't a superset of Python 2.7. While technically true, it's not useful to anyone but pedantics trying to start an argument
BlueRaja - Danny Pflughoeft
@Danny: But it is true. And the minimal effort required to write "C++ is, *for all intents and purposes*, a superset of C" is totally worth it.
You
@BlueRaja: I agree that in most cases it can be considered a superset, but there are some things that are supported in C and not in C++, like arrays whose size is defined at runtime: `void f( int x ) { int a[x]; }` And there are subtleties, like `void f(); void f( int i ) {}` in C defines a single function that takes an argument, in C++ it declares a function with no arguments and an overload with one argument...
David Rodríguez - dribeas
@David: Arrays whose size is defined at runtime is not an exactly well supported item in C.
Billy ONeal
@Billy: Visual Studio is the only compiler I know of that has no C99 support --and probably never will. The rest of the compilers I know (gcc, intel, sun, comeau) all have support for variable size arrays. Whether a single vendor make it *not exactly well supported* is debatable, kind of *POSIX is not a well supported standard*, as there are some OS that don't comply with it.
David Rodríguez - dribeas
+7  A: 

You can use the "not yet official" boost.process if you want an object-oriented approach for managing the subprocess.

Or you can just use popen itself, if you don't mind the C-ness of it all.

Stephen
+4  A: 

There is no C++ equivalent in any Standard, however C++ wrappers around this function (and other POSIX process function) can be found in various UI Toolkit (e.g QT, glibmm) and in the pstreams library.

lunaryorn