Question:
Difference between popen and _popen C++?
Fred
2011-05-22 06:30:58 UTC
Anyone know the difference, that is, if there is a difference? In VS 2010 _popen works but popen doesn't, yet in WXdev, they both work. Any ideas why?

Also, anyone know why of an alternative to _popen because it seems a little dodgy and it's also not part of the standard C++ library.
Four answers:
Cubbi
2011-05-23 07:00:23 UTC
Neither function is part of C++.



popen() is a POSIX function, described here: http://pubs.opengroup.org/onlinepubs/9699919799/functions/popen.html



_popen() is a Windows API function, described here: http://msdn.microsoft.com/en-us/library/96ayss4b(v=VS.100).aspx



There is nothing dodgy about using OS-specific functions to request the OS to perform OS-specific tasks such as launching another process.
Solange
2015-08-19 01:35:51 UTC
This Site Might Help You.



RE:

Difference between popen and _popen C++?

Anyone know the difference, that is, if there is a difference? In VS 2010 _popen works but popen doesn't, yet in WXdev, they both work. Any ideas why?



Also, anyone know why of an alternative to _popen because it seems a little dodgy and it's also not part of the standard C++ library.
peteams
2011-05-22 07:03:52 UTC
An _ at the start of a name means the name is somewhat non-standard. So _popen in Visual C++ says it's non-standard, whereas the WXdev is offering it both as a "standard" and non-standard flavour.



Since the command executes a shell command it is inherently non-standard, different operating systems have different commands available.



The alternative you seek is to do whatever you want the command to do yourself without using a shell command.
?
2016-12-08 17:20:40 UTC
Windows Popen


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...