[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dup2() on stdout [or using disp() on another file stream]
From: |
Joao Cardoso |
Subject: |
Re: dup2() on stdout [or using disp() on another file stream] |
Date: |
Sat, 23 Oct 1999 18:40:47 +0100 |
"John W. Eaton" wrote:
> On 16-Oct-1999, Joao Cardoso <address@hidden> wrote:
>
> | How can I use 'disp' on a file stream other than 'stdout'?
> |
> | 'disp' is an easy and nice way to print matrices, without the need to
> | create a format string to use on 'fprintf'. I would like to:
> |
> | f_name = tmpnam
> | fout = fopen(f_name,"w");
> | disp(fout, rand(3)) <--- not supporred
> | fclose(fout)
> |
> | When I tried to use:
> |
> | f_name = tmpnam
> | fout = fopen(f_name,"w");
> | old = fopen("old","w");
> |
> | dup2(stdout, old); # save old stdout on 'old'?
> | dup2(fout, stdout); # use new stdout
> |
> | disp(rand(3))
> |
> | dup2(old, stdout); #revert to saved stdout?
> |
> | I wasn't able to revert stdout to the original stdout. what is wrong? I
> | can't 'fclose(stdout)', either.
...
> Perhaps it would be better to just implement an fdisp() function that
> does what you want? Or, in the current bleeding-edge sources, Octave
> has a `file' data type and a C++-like output operator, so you can
> write:
>
> file = fopen (fname, "w");
> file << rand (3);
this is fine. Thanks.
> to print a formatted matrix to a file.
>
> (I'm not sure that the `<<' operator is a good idea though -- this feature is
> still experimental.)
yes, too much C++ alike for Octave, I think. But the general idea is fine, and
after all Octave future is not to be a static one, neither whatever Matlab
designers think that is best appropriate.
Joao
>
>
> jwe
--
Joao Cardoso | e-mail: address@hidden
INESC, R. Jose Falcao 110 | tel: + 351 2 2094322
4050 Porto, Portugal | fax: + 351 2 2008487
---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL. To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------