#include #include #include "Python.h" int main() { int fds[2]; _pipe(fds, 1024, O_BINARY); _dup2(fds[1], 1); setvbuf(stdout, NULL, _IONBF, 0); /* alternative version: */ // HANDLE hReadPipe, hWritePipe; // int fd; // DWORD nr; // CreatePipe(&hReadPipe, &hWritePipe, NULL, 0); // fd = _open_osfhandle((intptr_t)hWritePipe, _O_BINARY); // _dup2(fd, 1); // setvbuf(stdout, NULL, _IONBF, 0); write(1, "write\n", 6); printf("printf\n"); Py_Initialize(); PyRun_SimpleString("print 'print'"); // this breaks Py_Finalize(); char buffer[1024]; fprintf(stderr, "buffer size: %d\n", read(fds[0], buffer, 1024)); // should always be more than 0 /* alternative version: */ // CloseHandle(hWritePipe); // char buffer[1024]; // ReadFile(hReadPipe, buffer, 1024, &nr, NULL); // fprintf(stderr, "buffer size: %d\n", nr); // should always be more than 0 }