Capturing the output of "diff" with org-babel
Asked Answered
A

2

11

I'm trying to capture the output of diff with org-babel, but for some reason it's not working. For the files

1

a b c

2

a c b

diff 1 2 called from the command line returns

1c1
< a b c
---
> a c b

But with org-babel, nothing:

#+begin_src sh                                                                                                                                                 
diff 1 2                                                                                                                                                       
#+end_src                                                                                                                                                      

#+RESULTS:

The minibuffer reads "Code block produced no output". The org-babel error output window is empty. Other commands such as ls show the output as expected. I'm not familiar with org-babel.

I tried using :results output verbatim, no changes. I also tried using :results output replace as suggested here. Didn't help.

  • Emacs version is 24.4.1 (on Debian jessie)
  • Org-mode version is 8.2.10
A answered 4/12, 2014 at 21:30 Comment(1)
When diff finds that two files differ it returns with a non-zero exit code. org-babel seems to assume that if a block returns a non-zero exit code then the execution has failed and org-babel chokes.Obola
C
14

I could reproduce your problem (on OSX).

The strange thing is that executing the babel block will open the Org-babel Error Output buffer, as if something were going to STDERR.

If you add any other output after diff, results will display OK. For example,

#+begin_src sh :results output
diff 1 2
echo
#+end_src

If you force diff's results to stdout, results will also display:

#+begin_src sh :results output
diff 1 2 | cat
#+end_src
Cordell answered 5/12, 2014 at 11:49 Comment(6)
@A Did you ever submit that bug? If so, I'll add a patch to it - if not, I'll submit my own, with a patch.Kangaroo
@AaronMiller I don't remember. I'd suggest you add your own.A
@AaronMiller: Did something happen with this issue? I just got the same problem, and the same workaround applies.Despond
@MeaningfulUsername Never had a chance to follow up.Kangaroo
3 years and the bug is still out there.Ingeborg
5 years and a couple monthsAldas
A
3

Looks like org-babel doesn't like it when the return code isn't 0. That's why the various solutions work. Adding another command uses means that the overall error code of the block is success. Similarly piping into cat makes the pipeline return the error code of cat. Yet another way of eating the error condition is:

  diff 1 2 || true
Agamic answered 28/1, 2020 at 2:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.