[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SUGGESTION] ob-shell async result output should not contains shell

From: Matt
Subject: Re: [SUGGESTION] ob-shell async result output should not contains shell prompt
Date: Thu, 23 Mar 2023 12:23:50 -0400
User-agent: Zoho Mail

 ---- On Thu, 23 Mar 2023 07:12:29 -0400  Christopher M. Miles  wrote --- 
 > #+begin_src bash :session "*ob-shell-bash*" :async t
 > sleep 30
 > echo "hello, world"
 > #+end_src
 > #+RESULTS[(2023-03-23 19:14:15) 23f9ad130f7a1268e21821c6baaea2b057c70d3e]:
 > : org_babel_sh_prompt> hello, world
 > Still got a prompt. Is this intended? I think the output should be kept 
 > clean because the result
 > output might be used as input for other source blocks as data.

I absolutely agree.  This is a bug.  

It should be an easy fix on my end but, in case there are details I'm 
overlooking, this specific example can use the following workaround:

#+begin_src bash :session "*ob-shell-bash*" :async t
sleep 30 && echo "hello, world"

To explain what's going on...

Shell output is filtered for prompts which should be removed before inserting 
the results.  The issue is that the filter assumes the prompt starts at the 
beginning of the line.  When sleep is called, it returns nothing and the next 
prompt appears on the same line:

sh-5.1$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo 
echo "1"
sleep 3
echo "2"
echo 'ob_comint_async_shell_end_770d9c8f-deda-4359-aee9-a433a75a5e0d'
org_babel_sh_prompt> 1
org_babel_sh_prompt> org_babel_sh_prompt> 2

Changing the `ob-shell-async-chunk-callback' like this will fix it:

@@ -276,7 +276,7 @@ See `org-babel-comint-async-indicator'.")
 (defun ob-shell-async-chunk-callback (string)
   "Filter applied to results before insertion.
 See `org-babel-comint-async-chunk-callback'."
-  (replace-regexp-in-string comint-prompt-regexp "" string))
+  (replace-regexp-in-string (concat (regexp-quote org-babel-sh-prompt) " *") 
"" string))
 (defun org-babel-sh-evaluate (session body &optional params stdin cmdline)
   "Pass BODY to the Shell process in BUFFER.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]