M
Mark Probert
Hi ..
Any ideas on how to redirect stdout in an extension and then revert it
back to its default behaviour? freopen() redirects, though I am not
sure of returning to normal programming.
So,
VALUE rb_dump(VALUE self, VALUE o_name)
{
VALUE rval; /* our result */
VALUE fname; /* holds the filename */
fname = StringValue(o_name);
/* redirect stdout */
freopen("a.xml", "w+", stdout);
if (foo_dump(STR2CSTR(fname)) == -1) {
rval = Qnil;
} else {
rval = Qtrue;
}
fclose(stdout); /* bad!!! want to go back to fd 1 */
return rval;
}
BTW, I have no way of modifying the call to foo_dump() to take a file
handle. It just splurts out to stdout.
Many thanks,
Any ideas on how to redirect stdout in an extension and then revert it
back to its default behaviour? freopen() redirects, though I am not
sure of returning to normal programming.
So,
VALUE rb_dump(VALUE self, VALUE o_name)
{
VALUE rval; /* our result */
VALUE fname; /* holds the filename */
fname = StringValue(o_name);
/* redirect stdout */
freopen("a.xml", "w+", stdout);
if (foo_dump(STR2CSTR(fname)) == -1) {
rval = Qnil;
} else {
rval = Qtrue;
}
fclose(stdout); /* bad!!! want to go back to fd 1 */
return rval;
}
BTW, I have no way of modifying the call to foo_dump() to take a file
handle. It just splurts out to stdout.
Many thanks,