emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Michaël Cadilhac" <michael@cadilhac.name>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Org-Mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Can I get the results of shell code block when exit code is non-zero?
Date: Thu, 29 Aug 2019 11:13:09 -0500	[thread overview]
Message-ID: <CADt3fpP4rj6SkbJvc-mp1Um3-v9j1ojrERUgsu99HvGi7PvXiw@mail.gmail.com> (raw)
In-Reply-To: <87k1awa1mn.fsf@mbork.pl>

[-- Attachment #1: Type: text/plain, Size: 1531 bytes --]

Hi there,

This is the expected behavior, implemented in `org-babel-eval`. (By the
way, the docline of `org-babel-sh-evaluate` seems to talk about a different
function.)

As a workaround, you could define a new shell that always returns 0:

(push "0bash" org-babel-shell-names)
(org-babel-shell-initialize)
(defun org-babel-execute:0bash (body params)
  "Execute a block of bash commands with Babel, returning 0."
  (let ((shell-file-name "bash"))
    (org-babel-execute:shell (concat "trap 'exit 0' EXIT\n" body) params)))

—This is called 0bash because there are special treatments if the shell
name ends with "bash", see `org-babel--variable-assignments:bash`.

Cheers,
M.

On Thu, 29 Aug 2019 at 02:10, Marcin Borkowski <mbork@mbork.pl> wrote:

> Hi all,
>
> apparently when the exit code of the last command in a shell code block
> is not zero, I do not get the results.  This doesn't seem to be
> documented in the manual (though I might be missing something).  Check
> this:
>
> #+begin_src bash :results verbatim
>   echo hello world
>   exit 0
> #+end_src
>
> and this:
>
> #+begin_src bash :results verbatim
>   echo hello world
>   exit 1
> #+end_src
>
> How can I tell Org to put the results in the file anyway?  My use case
> is =diff=, which exists with status 1 if differences are found, and this
> is a blog post, so I do not want to pollute the post with an =exit 0= at
> the end of the code snippet.
>
> TIA,
>
> --
> Marcin Borkowski
> http://mbork.pl
>
>

[-- Attachment #2: Type: text/html, Size: 2133 bytes --]

      reply	other threads:[~2019-08-29 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-29  7:09 Can I get the results of shell code block when exit code is non-zero? Marcin Borkowski
2019-08-29 16:13 ` Michaël Cadilhac [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADt3fpP4rj6SkbJvc-mp1Um3-v9j1ojrERUgsu99HvGi7PvXiw@mail.gmail.com \
    --to=michael@cadilhac.name \
    --cc=emacs-orgmode@gnu.org \
    --cc=mbork@mbork.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).