You are not logged in.

#1 2012-09-17 00:15:23

commx
Member
Registered: 2012-06-11
Posts: 13

(C) Redirecting stdout to a buffer

I'm currently authoring a python binding for a third-party application. A function of the third-party applications allows users to set the filename to "-" which will then print the result to stdout. I'd like to be able to catch that output into a buffer and handle it entirely in memory rather than creating a temporary file on disk (that's why freopen does not fit for this). Can someone give me a hint?

Offline

#2 2012-09-17 00:31:32

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: (C) Redirecting stdout to a buffer

It's not possible to do such a thing in standard C (that is, without POSIX extensions). Instead, try looking at popen(3).

Offline

#3 2012-09-17 19:10:05

commx
Member
Registered: 2012-06-11
Posts: 13

Re: (C) Redirecting stdout to a buffer

POSIX is fine. It may be great to have a platform-independent way for doing this, but I found my solution with glibc's open_memstream().

Offline

Board footer

Powered by FluxBB