From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id YIfQKVFBUmR7bwAASxT56A (envelope-from ) for ; Wed, 03 May 2023 13:11:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id sNwSKVFBUmRvVQAAG6o9tA (envelope-from ) for ; Wed, 03 May 2023 13:11:13 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 72B0911C18 for ; Wed, 3 May 2023 13:11:13 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puANQ-0002cK-0V; Wed, 03 May 2023 07:10:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puANL-0002Vp-TE for emacs-orgmode@gnu.org; Wed, 03 May 2023 07:10:23 -0400 Received: from [39.171.215.100] (helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puANJ-00069e-IT for emacs-orgmode@gnu.org; Wed, 03 May 2023 07:10:23 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id 0EE358AE9DB6; Wed, 3 May 2023 19:10:02 +0800 (CST) References: <87354hs9pz.fsf@localhost> <87mt2oqyup.fsf@localhost> <187de29d882.c92c2b661216812.7786590004610447376@excalamus.com> <878re5g0ir.fsf@localhost> User-agent: mu4e 1.10.3; emacs 30.0.50 From: "Christopher M. Miles" To: Ihor Radchenko Cc: Matt , emacs-orgmode@gnu.org Subject: Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Date: Wed, 03 May 2023 19:01:18 +0800 In-reply-to: <878re5g0ir.fsf@localhost> Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Host-Lookup-Failed: Reverse DNS lookup failed for 39.171.215.100 (deferred) Received-SPF: softfail client-ip=39.171.215.100; envelope-from=numbchild@gmail.com; helo=Mac-mini.local X-Spam_score_int: 58 X-Spam_score: 5.8 X-Spam_bar: +++++ X-Spam_report: (5.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, MSGID_MULTIPLE_AT=1, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_PBL=3.335, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665, SPOOFED_FREEMAIL_NO_RDNS=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: reject X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: numbchild@gmail.com Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1683112273; a=rsa-sha256; cv=none; b=VC/B7/bthdLnOIgBvQeuPiZ2gmqYiuKfDbEQ4sZfCZ3za7BZ7cYPDepBxUAi7PkOY2NRBs g8cSlRMLkO6Xsrm2hZ+kals3YuUgB8RGiuyD9owbsZC5AitkNPLkFCxN3i6SBFKREmIiFz DQ82VdWW3iNqBzaKBiuyXPRo1QP/Dq59fpkONh80JKePYbx3JoCgvx90yWpkWtv4qCKx+M VuhKYMgD6YMcZEfSFdLvNBV2AvJBFDHsmP2l47y5SVHrOoGNR0dxwv7LDjZTqOGIjkahE9 DlHmrB6pb2C7Px5HIyWBOxF/ys5Xzvwx/rh73EYK5o8Z981mkU1Jc0515YedVg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1683112273; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=z44WnYUHNeIq5jDFVUsQQdr9lSgsq+lbECrMZq2PB48=; b=OQlMvwpy1VilofeRNWlbVQkQFQ1KJsITKaVqiXW7QY0LcrtG8o+P92yFaeHeyiIlyRSTtx e8Hv87l5bq0V1/DiDvJkK9wc09eBJ85QGOZis7JopJYTWyC0cv6c7A+qjUC37OIMqEsVwe 8PNCBqHD1Lt1JbwdPLN0jqPW5jLQttqJw9LVXvz+UtmZV9PceToHwonD8jMjm6HG+7jU0f IbVpAX2T3DZ+48pveOnHfhTKr3sXHtqfdHbJmKyCxK19/fJyXlKRq77AhgJpF4zBPu8vRq MwX3uoOWcx51V9ONKdd+1Gn1Va59wmqOJPPof1IaQqCwloowqbdjve/Qj5xp4w== X-Migadu-Spam-Score: -2.91 X-Spam-Score: -2.91 X-Migadu-Queue-Id: 72B0911C18 X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-TUID: KeTqJfxxZORz --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ihor Radchenko writes: > Matt writes: > >> > Matt, maybe you have some ideas about this edge case? >> >> I have no other ideas within the current ob-shell implementation. As fo= r modifications, I have the following thoughts. >> >> First, how might we state the problem for this edge case? >> >> To me, it looks like, "How can the ob-shell :async option manage interac= tive input?" Do you agree >> with this formulation? If not, how do you see it differently? > > It is not about :async per se. Rather about using :session. > > A simple reproducer is > > #+begin_src bash :session test > mpv "/path/to/some/video" > m_ > #+end_src > > Basically, when you send multiline command in comint buffer without > waiting for each line to finish, the following line may be read by the > running command if that command is interactive. > > It is similar to a situation when you run a normal terminal like > > $ mpv "..." > > > $ m_ > Indeed, this explaination give me more clear understanding of the problem. So currently ob-shell.el is async sending command into session buffer without waiting for command to be finished. I checked out the ob-shell.el source code. I suppose this is the core part of the problem. From intuitive view, session async evaluation indeed should not wait for command to be finished. But still feel a little weird. #+begin_src emacs-lisp (session ; session evaluation (if async (progn (let ((uuid (org-id-uuid))) (org-babel-comint-async-register session (current-buffer) "ob_comint_async_shell_\\(.+\\)_\\(.+\\)" 'ob-shell-async-chunk-callback nil) (org-babel-comint-async-delete-dangling-and-eval session (insert (format ob-shell-async-indicator "start" uuid= )) (comint-send-input nil t) (insert (org-trim body)) (comint-send-input nil t) (insert (format ob-shell-async-indicator "end" uuid)) (comint-send-input nil t)) uuid)) (mapconcat #'org-babel-sh-strip-weird-long-prompt (mapcar #'org-trim (butlast ; Remove eoe indicator (org-babel-comint-with-output (session org-babel-sh-eoe-output t body) (insert (org-trim body) "\n" org-babel-sh-eoe-indicator) (comint-send-input nil t)) ;; Remove `org-babel-sh-eoe-indicator' output line. 1)) "\n"))) #+end_src >> One thought is to update :async to work with the :stdin option so that >> the block is run as a script. Currently, :stdin runs synchronously in >> a separate shell. We might be able to grab the script's output and put >> it into the session buffer. See how the following runs in a temporary >> shell, regardless of the :session/:async options. > > Avoiding session altogether will indeed solve the problem, as :session > is the place where the problem lies. > > Adding :stdin support is also an interesting idea, even out of scope of > this discussion. If this :stdin interesting idea works, maybe other similar ideas will too.= =F0=9F=99=8B For examples: =2D Wrap command "mpv" with a shell function which disable accepting intera= ctive input. =2D Setting shell or environment variable in :prolog for source block to pr= eventing interactive input. Anyway, glad to get more interesting ideas. =2D-=20 [ stardiviner ] I try to make every word tell the meaning that I want to express without mi= sunderstanding. Blog: https://stardiviner.github.io/ IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmRSQQoACgkQG13xyVro msNNcQf+NSQdK1aE+050pb4vVWMfm7QMJTrWMB2Hzr8Wsb9dAHBbDFUwrWyGst+J 13PS5V2c1HpA/9xsMiikrd3kWWuOkntDSZ4x5Ce1ZiTnIZlnlXHLmfra7KsP+NJw UV2AdQ1JRuFGAxgR2sNiFMsIA/awsBoNKAhS+bt+qQrgCJ4GrXDU/OZ35pxt0BR2 rbnTuYQHWmjZlf40zxGSkAKdT3ivK7/9bPtP8x8NpshVX5WI7+1NMucvDhsSse15 bEEOe+l5We7wijyzhae7Qd/7zd4pgPX57rbrdKD18TmA+XfoJUaOGHOX072306Zi l59f1KSLDs1eQN8RA8Q+zs81S6e2+Q== =g0N+ -----END PGP SIGNATURE----- --=-=-=--