From mboxrd@z Thu Jan 1 00:00:00 1970 From: Diego Zamboni Subject: Re: How to intersperse commands with their output in RESULTS block? Date: Fri, 7 Feb 2020 16:26:00 +0100 Message-ID: References: <871rr86w8p.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000068cf8b059dfe0233" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:40246) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j05WJ-0001xn-3V for emacs-orgmode@gnu.org; Fri, 07 Feb 2020 10:26:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j05WH-000863-FS for emacs-orgmode@gnu.org; Fri, 07 Feb 2020 10:26:14 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:38111) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j05WG-00085G-Sq for emacs-orgmode@gnu.org; Fri, 07 Feb 2020 10:26:13 -0500 Received: by mail-wr1-x42f.google.com with SMTP id y17so3163244wrh.5 for ; Fri, 07 Feb 2020 07:26:12 -0800 (PST) In-Reply-To: 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-mx.org@gnu.org Sender: "Emacs-orgmode" To: "Fraga, Eric" Cc: Org-mode --00000000000068cf8b059dfe0233 Content-Type: text/plain; charset="UTF-8" Hi everyone, Quick follow up about this: following Eric's suggestion, I came up with the following block, which cleans up all the cruft from the output of the =script= command and produces a nicely formatted session transcript: #+NAME: cleanup #+BEGIN_SRC emacs-lisp :var data="" :results value :exports none (replace-regexp-in-string "\\$ exit\\(.\\|\n\\)*$" "" (replace-regexp-in-string "^bash-.*\\$" "$" (replace-regexp-in-string "\\(\\(.\\|\n\\)*?\\)\\$\\(.\\|\n\\)*\\'" "" (replace-regexp-in-string " " "" data) nil nil 1))) #+END_SRC (I am not happy with the regexp nesting and repetition above, I am not an expert yet in emacs-lisp regex facilities. Suggestions appreciated for how to simplify it). This produces exactly the result I need: #+begin_src sh :exports output :results output :wrap "src console" :post cleanup(data=*this*) script < wrote: > Hi Eric, > > Great idea! I hadn't considered using the =script= command, it's a great > starting point. > > Thanks! > --Diego > > > On Thu, Feb 6, 2020 at 7:55 AM Fraga, Eric wrote: > >> On Wednesday, 5 Feb 2020 at 18:25, Diego Zamboni wrote: >> > tl;dr: is there a way to have ob-shell (or some similar mode) run >> commands >> > one by one and include the commands, interspersed with their output, in >> the >> > #+RESULTS block? >> >> You haven't said on what type of system but, if Linux, you could try >> using =script= as a starting point: >> >> #+begin_src shell :results output >> script <> ls >> echo 'hello' >> EOF >> #+end_src >> >> You may wish to have a second shell script that massages the output in >> the =typescript= file and ouputs that instead, e.g. to filter the >> carriage returns. >> -- >> : Eric S Fraga via Emacs 28.0.50, Org release_9.3.2-233-gc2bc48 >> > --00000000000068cf8b059dfe0233 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi everyone,

Quick follow up about this: following Eric's suggestion, = I came up with the following block, which cleans up all the cruft from the = output of the =3Dscript=3D command and produces a nicely formatted session = transcript:

#+NAME: cleanup
#+BEGIN_SRC e= macs-lisp :var data=3D"" :results value :exports none
= =C2=A0 (replace-regexp-in-string
=C2=A0 =C2=A0"\\$ exit\\(.\= \|\n\\)*$" ""
=C2=A0 =C2=A0(replace-regexp-in-stri= ng
=C2=A0 =C2=A0 "^bash-.*\\$" "$"
= =C2=A0 =C2=A0 (replace-regexp-in-string
=C2=A0 =C2=A0 =C2=A0"= ;\\(\\(.\\|\n\\)*?\\)\\$\\(.\\|\n\\)*\\'" ""
= =C2=A0 =C2=A0 =C2=A0(replace-regexp-in-string "
" "= ;" data) nil nil 1)))
#+END_SRC

(I am not happy with the regexp nesting and repetition above, I am not a= n expert yet in emacs-lisp regex facilities. Suggestions appreciated for ho= w to simplify it).

This produces exactly the resul= t I need:

#+begin_src sh :exports output :res= ults output :wrap "src console" :post cleanup(data=3D*this*)
script <<EOF
echo hi
echo bye
EOF=
#+end_src

#+RESULTS:
#+begin_= src console
$ echo hi
hi
$ echo bye
bye
#+end_src

Thanks Eric!
<= div>
--Diego


On Thu, Feb 6, 2= 020 at 9:45 PM Diego Zamboni <dieg= o@zzamboni.org> wrote:
Hi Eric,

Great idea! I ha= dn't considered using the =3Dscript=3D command, it's a great starti= ng point.

Thanks!
--Diego

=

On Thu, Feb 6, 2020 at 7:55 AM Fraga, Eric <e.fraga@ucl.ac.uk> wrote:
=
On Wednesday,=C2=A0 5 Feb= 2020 at 18:25, Diego Zamboni wrote:
> tl;dr: is there a way to have ob-shell (or some similar mode) run comm= ands
> one by one and include the commands, interspersed with their output, i= n the
> #+RESULTS block?

You haven't said on what type of system but, if Linux, you could try using =3Dscript=3D as a starting point:

#+begin_src shell :results output
=C2=A0 script <<EOF
=C2=A0 ls
=C2=A0 echo 'hello'
=C2=A0 EOF
#+end_src

You may wish to have a second shell script that massages the output in
the =3Dtypescript=3D file and ouputs that instead, e.g. to filter the
carriage returns.
--
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.2-233-gc2bc48
--00000000000068cf8b059dfe0233--