Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent to Posix popen() in the Win32 API?

Is there a rough equivalent to the Linux/Unix stdio.h popen() function in the Win32 API? If so, where can I find it?

Edit: I need to know this to patch an omission in the D standard library. Any answer must use only standard Win32 API, no MSVC-specific functions. Also, I'd prefer something that's not horribly low-level, if it exists.

like image 921
dsimcha Avatar asked Jan 16 '09 15:01

dsimcha


People also ask

Does Popen work on Windows?

_popen works properly in a console application. To create a Windows application that redirects input and output, see Creating a Child Process with Redirected Input and Output in the Windows SDK.

What does Popen do in C++?

DESCRIPTION. The popen() function shall execute the command specified by the string command. It shall create a pipe between the calling program and the executed command, and shall return a pointer to a stream that can be used to either read from or write to the pipe.


2 Answers

MSDN explains how you do what popen does using the Windows API in Pipe Handle Inheritance . Here it provides a well-documented example. It's way more low-level than the _popen function found in the runtime library linked by Jason, but uses the Win32 API exclusively.

like image 72
Johannes Schaub - litb Avatar answered Oct 10 '22 20:10

Johannes Schaub - litb


You can call _popen if you're writing a console application. For more information, see the documentation on the MSDN site: http://msdn.microsoft.com/en-us/library/96ayss4b(VS.80).aspx

like image 39
Jason Coco Avatar answered Oct 10 '22 21:10

Jason Coco