[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Input redirection (was: Re: pb with oct file, return a matrix)
From: |
John W. Eaton |
Subject: |
Input redirection (was: Re: pb with oct file, return a matrix) |
Date: |
Wed, 8 Jul 2009 14:53:48 -0400 |
On 23-Apr-2009, Søren Hauberg wrote:
| tor, 23 04 2009 kl. 10:48 +0200, skrev Jaroslav Hajek:
| > you should use octave_stdout (pager.h) if you want your output to mix
| > with output of other functions normally. That includes going through
| > the pager if it is enabled. Writing directly to C's stdout bypasses
| > Octave's I/O mechanisms.
|
| I always wondered why this is the case. Could we just do something like
|
| std::cout.rdbuf (octave_stdout.rdbuf ()); // untested
|
| to send everything from stdout through the pager?
That does appear to work for cout, but it doesn't capture stdout. For
example, try the following function:
#include <octave/config.h>
#include <iostream>
#include <cstdio>
#include <octave/defun-dld.h>
#include <octave/pager.h>
DEFUN_DLD (xfoo, , , "")
{
std::cout.rdbuf (octave_stdout.rdbuf ());
int i = 0;
for (; i < 30; i++)
std::cout << i << std::endl;
for (; i < 60; i++)
printf ("%d\n", i);
return octave_value_list ();
}
jwe
- Input redirection (was: Re: pb with oct file, return a matrix),
John W. Eaton <=