octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

capture command output


From: John W. Eaton
Subject: capture command output
Date: Mon, 15 Dec 2003 23:18:22 -0600

On 15-Dec-2003, Paul Kienzle <address@hidden> wrote:

| For a few reasons, I want to be able to run
| a command and capture its output without it going
| to the screen.  One is for parallel octave --- if
| you execute stuff on another processor, you want
| to be able to send the screen output back to the
| controlling terminal.  Another is for embedded
| octave --- if you execute an octave command in
| tcl/tk, you want to be able to put its output in 
| a tcl/tk window.  A third reason is testing ---
| I want to be able to run the test example and 
| display a summary on the screen and have the 
| results in a file.
| 
| Using pager tricks, I can hack this (see the 
| "capture" command below), but I would rather
| not go through the file system.  
| 
| Having written a few DLD functions, I know that all
| screen output goes through octave_stdout.  I was 
| assuming this was simply a variable that I could 
| cache, replace with a my own stream, and restore when 
| I was done.  Alas, it is 
| 
|   #define octave_stdout (octave_pager_stream::stream ())
| 
| and of course the interesting bits of the class
| octave_pager_stream are private.

Even if octave_stdout were just a pointer to a C++ ostream, I don't
think you would want to reassign it to your own stream, because then
you would lose the diary.

| Any suggestions how we can do this from C++ and from
| the script level?
| 
| Error messages can already be buffered, but warnings
| cannot.
| 
| Thanks,
| 
| Paul Kienzle
| address@hidden
| 
| PS, Is there any way to override 'private'?  E.g.,
| by having your own copy of the header files with the word
| private replace by public whereever it occurs?  Or does the
| C++ ABI do something special when storing privates?

Rather than resorting to kluges like that, maybe all you need is a way
to write your own function to replace the do_sync function in
pager.cc.  The job of do_sync is to take output that is supposed to be
headed for the screen and actually send it there.  The diary is
handled by another function, so it seems that this would be the right
place to do what you want.  Perhaps we should provide a function
pointer that you could define and then modify Octave's do_sync
function to do

  static void
  do_sync (const char *msg, int len, bool bypass_pager)
  {
    if (msg && len > 0)
      {
        if (user_do_sync)
          user_do_sync (msg, len, bypass_pager);
        else
          {
            // rest of current function body...
          }
      }
  }

Then you could reroute the screen output however you like.

If we do this, I think we need names that are better than do_sync and
user_do_sync...

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]