K
Kenny McCormack
Tim Rentsch said:It looks like popen() does what you want, ...
No.
Please re-read.
Then get back to us, mmK?
Tim Rentsch said:It looks like popen() does what you want, ...
Of course i'm interested.
Here is the best i can do, based on all the remarks here (still no
posting in comp.unix.programming, as i did some research and reading
instead):
Tim Rentsch said:It looks like popen() does what you want, ...
No.
Please re-read. [snip]
It just occurred to me, why not just use "freopen()"?
Something like:
freopen("/tmp/mytmpfile","w",stdout);
// Invoke whatever things generate output on stdout
// Now read /tmp/mytmpfile into memory, parse it, do whatever you need to.
// (And then unlink() the file)
This is not quite as cool as having it write directly to
memory, but it is pretty simple to implement.
jseb said:Hello,
I'd like to bufferise stdout. That's it, when something is sent to
stdout FD, it goes instead to a buffer.
(it's for sending this buffer to another computer with network sockets).
I read that "open_memstren" could do that (posix function).
Here is my test:
///////////// CODE START /////////////////
#include<stdio.h>
#include<malloc.h>
#include<unistd.h>
int main(void)
{
char *buffer; //for open_memstream
size_t size;
FILE *memstream = open_memstream(&buffer, &size);
int stdout_copy = dup(1); //save stdout
stdout = memstream; //redirection
Of course i'm interested.
One of the larger problems with this approach is:
One of the larger problems with this approach is:
foo.c: error: 'FILE' has no member named '_cnt'
although it might work on the particular platform you are interested in.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.