emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BABEL] Redirect stderr to stdout?
@ 2012-03-02 11:29 Viktor Rosenfeld
  2012-03-02 16:21 ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Viktor Rosenfeld @ 2012-03-02 11:29 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

is there a way to capture stderr output of a babel block and have it
appear in the results block (instead of being printed in the *Shell
Command Output* buffer)? On sh blocks I could redirect myself, but I'm
trying to capture the output of psql (the PostgreSQL client).

Specifically, I have the following code block:

#+BEGIN_SRC sql :noweb yes :results output verbatim
\timing on
<<exp8-test-query>>
#+END_SRC

#+RESULTS:
: count
: 95977

The \timing directive causes psql to print the runtime of the query on
stderr. If I run the query on the psql command line, the following
output appears:

 count 
 -------
 95977
 (1 row)

 Time: 1895,558 ms

I suppose that duplicating this output in Babel would be difficult,
because it interferes with the parsing of the result set.

Cheers,
Viktor

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BABEL] Redirect stderr to stdout?
  2012-03-02 11:29 [BABEL] Redirect stderr to stdout? Viktor Rosenfeld
@ 2012-03-02 16:21 ` Eric Schulte
  2012-03-02 19:47   ` Viktor Rosenfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2012-03-02 16:21 UTC (permalink / raw)
  To: emacs-orgmode

Viktor Rosenfeld <listuser36@googlemail.com> writes:

> Hi,
>
> is there a way to capture stderr output of a babel block and have it
> appear in the results block (instead of being printed in the *Shell
> Command Output* buffer)? On sh blocks I could redirect myself, but I'm
> trying to capture the output of psql (the PostgreSQL client).
>
> Specifically, I have the following code block:
>
> #+BEGIN_SRC sql :noweb yes :results output verbatim
> \timing on
> <<exp8-test-query>>
> #+END_SRC
>
> #+RESULTS:
> : count
> : 95977
>
> The \timing directive causes psql to print the runtime of the query on
> stderr. If I run the query on the psql command line, the following
> output appears:
>
>  count 
>  -------
>  95977
>  (1 row)
>
>  Time: 1895,558 ms
>
> I suppose that duplicating this output in Babel would be difficult,
> because it interferes with the parsing of the result set.
>

Hi Viktor,

Currently the only action Babel takes with STDERR is to display it in a
pop-up buffer when code block evaluation fails.  It would certainly be
possible to add :results header argument to incorporate STDERR into
results (and this desire has been expressed previously).  Reasonable
combination options would likely include (at least) the following.

| stderr-only | return stderr instead of stdout    |
| 2>&1        | interleave stderr and stdout       |
| concat      | add stderr to the end of stdout    |
| list        | return a list of stderr and stdotu |

The best (read simple and extensible) implementation and syntax for this
behavior is not obvious to me (and I simply don't have time).  If you
(or anyone on the list) have any interest in hacking elisp code the
place to start would be `org-babel-eval' for a serious implementation,
or an quick hack may be possible through customization of the
`org-babel-eval-error-notify' function.

Hope this helps.

Best,

>
> Cheers,
> Viktor
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BABEL] Redirect stderr to stdout?
  2012-03-02 16:21 ` Eric Schulte
@ 2012-03-02 19:47   ` Viktor Rosenfeld
  2012-03-02 20:23     ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Viktor Rosenfeld @ 2012-03-02 19:47 UTC (permalink / raw)
  To: emacs-orgmode

Hi Eric,

Eric Schulte wrote:

> Currently the only action Babel takes with STDERR is to display it in a
> pop-up buffer when code block evaluation fails.  

On my system (OS X) the buffer does not popup. I just tried

#+BEGIN_SRC sh
echo foo 1>&2
#+END_SRC

in Aquamacs and Cocoa Emacs. Strangely, the output seems to be lost
entirely. Normally, stderr is captured in another buffer which I have to
open manually.

> It would certainly be
> possible to add :results header argument to incorporate STDERR into
> results (and this desire has been expressed previously).  Reasonable
> combination options would likely include (at least) the following.
> 
> | stderr-only | return stderr instead of stdout    |
> | 2>&1        | interleave stderr and stdout       |
> | concat      | add stderr to the end of stdout    |
> | list        | return a list of stderr and stdotu |
> 
> The best (read simple and extensible) implementation and syntax for this
> behavior is not obvious to me (and I simply don't have time).  If you
> (or anyone on the list) have any interest in hacking elisp code the
> place to start would be `org-babel-eval' for a serious implementation,
> or an quick hack may be possible through customization of the
> `org-babel-eval-error-notify' function.
> 
> Hope this helps.

Okay, thanks. My elisp skills are very rudimentary and this is beyond
me. Maybe somebody else will pick it up if the interest is big enough.

Cheers,
Viktor

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BABEL] Redirect stderr to stdout?
  2012-03-02 19:47   ` Viktor Rosenfeld
@ 2012-03-02 20:23     ` Eric Schulte
  2012-03-03 15:52       ` Viktor Rosenfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2012-03-02 20:23 UTC (permalink / raw)
  To: emacs-orgmode

Viktor Rosenfeld <listuser36@googlemail.com> writes:

> Hi Eric,
>
> Eric Schulte wrote:
>
>> Currently the only action Babel takes with STDERR is to display it in a
>> pop-up buffer when code block evaluation fails.  
>
> On my system (OS X) the buffer does not popup. I just tried
>
> #+BEGIN_SRC sh
> echo foo 1>&2
> #+END_SRC
>

That is because the evaluation did not fail, try

#+BEGIN_SRC sh
echo foo 1>&2
exit 1
#+END_SRC

>
> in Aquamacs and Cocoa Emacs. Strangely, the output seems to be lost
> entirely.

I don't pretend to understand the many oddities of Aquamacs, and I don't
know what Cocoa Emacs is.

> Normally, stderr is captured in another buffer which I have to open
> manually.
>
>> It would certainly be
>> possible to add :results header argument to incorporate STDERR into
>> results (and this desire has been expressed previously).  Reasonable
>> combination options would likely include (at least) the following.
>> 
>> | stderr-only | return stderr instead of stdout    |
>> | 2>&1        | interleave stderr and stdout       |
>> | concat      | add stderr to the end of stdout    |
>> | list        | return a list of stderr and stdotu |
>> 
>> The best (read simple and extensible) implementation and syntax for this
>> behavior is not obvious to me (and I simply don't have time).  If you
>> (or anyone on the list) have any interest in hacking elisp code the
>> place to start would be `org-babel-eval' for a serious implementation,
>> or an quick hack may be possible through customization of the
>> `org-babel-eval-error-notify' function.
>> 
>> Hope this helps.
>
> Okay, thanks. My elisp skills are very rudimentary and this is beyond
> me. Maybe somebody else will pick it up if the interest is big enough.
>

This feature has been requested previously on the mailing list, so there
is certainly demand.  As always demand outstrips development resources.

Best,

>
> Cheers,
> Viktor
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BABEL] Redirect stderr to stdout?
  2012-03-02 20:23     ` Eric Schulte
@ 2012-03-03 15:52       ` Viktor Rosenfeld
  0 siblings, 0 replies; 5+ messages in thread
From: Viktor Rosenfeld @ 2012-03-03 15:52 UTC (permalink / raw)
  To: emacs-orgmode

Hi Eric,

Eric Schulte wrote:

> Viktor Rosenfeld <listuser36@googlemail.com> writes:
> 
> > Hi Eric,
> >
> > Eric Schulte wrote:
> >
> >> Currently the only action Babel takes with STDERR is to display it in a
> >> pop-up buffer when code block evaluation fails.  
> >
> > On my system (OS X) the buffer does not popup. I just tried
> >
> > #+BEGIN_SRC sh
> > echo foo 1>&2
> > #+END_SRC
> >
> 
> That is because the evaluation did not fail, try
> 
> #+BEGIN_SRC sh
> echo foo 1>&2
> exit 1
> #+END_SRC

Thanks, that did the trick. It also explains why some error output from
psql and the like does not make it into the buffer.

> [Snip]
> 
> As always demand outstrips development resources.

And still, org-mode is great product!

Cheers,
Viktor

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-03-03 15:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-02 11:29 [BABEL] Redirect stderr to stdout? Viktor Rosenfeld
2012-03-02 16:21 ` Eric Schulte
2012-03-02 19:47   ` Viktor Rosenfeld
2012-03-02 20:23     ` Eric Schulte
2012-03-03 15:52       ` Viktor Rosenfeld

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).