Is their any C popen() equivalent in C++ to ?
I don't think that popen is required by the Standard.
DeadMG
2010-07-06 21:55:55
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
2010-07-06 21:58:22
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
2010-07-06 21:59:45
Technically, C++ isn't a superset of C.
You
2010-07-06 22:03:18
I know popen is available in c++. But I am flexible C++ iostream.
Arif
2010-07-06 22:26:23
@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
2010-07-06 22:37:31
@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
2010-07-06 22:43:11
@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
2010-07-06 22:46:37
@David: Arrays whose size is defined at runtime is not an exactly well supported item in C.
Billy ONeal
2010-07-06 23:51:36
@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
2010-07-07 07:36:09
+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
2010-07-06 21:59:28
+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
2010-07-06 22:05:37