From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Micha=C3=ABl_Cadilhac?= 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 Message-ID: References: <87k1awa1mn.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000004c1d7b059143caa8" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:38579) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3N3X-0008RZ-Il for emacs-orgmode@gnu.org; Thu, 29 Aug 2019 12:13:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3N3W-0001EH-1W for emacs-orgmode@gnu.org; Thu, 29 Aug 2019 12:13:51 -0400 Received: from cadilhac.name ([163.172.56.42]:38774 helo=mattermost.cadilhac.name) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i3N3V-0001DC-PK for emacs-orgmode@gnu.org; Thu, 29 Aug 2019 12:13:49 -0400 Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) by mattermost.cadilhac.name (OpenSMTPD) with ESMTPSA id a64eedd0 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for ; Thu, 29 Aug 2019 16:13:47 +0000 (UTC) Received: by mail-vk1-f177.google.com with SMTP id t136so907133vkt.9 for ; Thu, 29 Aug 2019 09:13:47 -0700 (PDT) In-Reply-To: <87k1awa1mn.fsf@mbork.pl> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Marcin Borkowski Cc: Org-Mode mailing list --0000000000004c1d7b059143caa8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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))) =E2=80=94This is called 0bash because there are special treatments if the s= hell name ends with "bash", see `org-babel--variable-assignments:bash`. Cheers, M. On Thu, 29 Aug 2019 at 02:10, Marcin Borkowski 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 =3Ddiff=3D, which exists with status 1 if differences are found, and t= his > is a blog post, so I do not want to pollute the post with an =3Dexit 0=3D= at > the end of the code snippet. > > TIA, > > -- > Marcin Borkowski > http://mbork.pl > > --0000000000004c1d7b059143caa8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi there,

This is the expected behavior= , implemented in `org-babel-eval`. (By the way, the docline of `org-babel-s= h-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)=
=C2=A0 "Execute a block of bash commands with Babel, returning 0.&= quot;
=C2=A0 (let ((shell-file-name "bash"))
=C2=A0 =C2=A0 = (org-babel-execute:shell (concat "trap 'exit 0' EXIT\n" b= ody) params)))

=E2=80=94This is called 0bash b= ecause there are special treatments if the shell name ends with "bash&= quot;, see `org-babel--variable-assignments:bash`.

Cheers,
M.

On Thu, 29 Aug 2019 at 02:10, Marcin Borkowski &= lt;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.=C2=A0 This doesn't seem to be documented in the manual (though I might be missing something).=C2=A0 Check=
this:

#+begin_src bash :results verbatim
=C2=A0 echo hello world
=C2=A0 exit 0
#+end_src

and this:

#+begin_src bash :results verbatim
=C2=A0 echo hello world
=C2=A0 exit 1
#+end_src

How can I tell Org to put the results in the file anyway?=C2=A0 My use case=
is =3Ddiff=3D, which exists with status 1 if differences are found, and thi= s
is a blog post, so I do not want to pollute the post with an =3Dexit 0=3D a= t
the end of the code snippet.

TIA,

--
Marcin Borkowski
http://mbo= rk.pl

--0000000000004c1d7b059143caa8--