From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha@kamnitnik.top Newsgroups: gmane.emacs.devel Subject: Re: comint-output-filter-functions and multi-line input Date: Mon, 17 Oct 2022 23:23:58 +0200 Message-ID: <87v8oidtzl.fsf@miha-pc> References: <87y1tgqhmc.fsf@localhost> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8843"; mail-complaints-to="usenet@ciao.gmane.io" To: Ihor Radchenko , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 17 23:26:38 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okXd7-00028C-NZ for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 23:26:38 +0200 Original-Received: from localhost ([::1]:49148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okXd6-00051J-JZ for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 17:26:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okXaq-0002mq-Rs for emacs-devel@gnu.org; Mon, 17 Oct 2022 17:24:16 -0400 Original-Received: from kamnitnik.top ([209.250.245.214]:45208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okXab-0004F4-Mg for emacs-devel@gnu.org; Mon, 17 Oct 2022 17:24:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1666041835; bh=hvo2XuvwSOCdWYIlJsg4gEd/Wd+He3qOYAAjw4s2gRc=; h=From:To:Subject:In-Reply-To:References:Date:From; b=NktmwO9JqZg4bdTXqQheLm91negnoPDiQj4rttwxzP24DZXReiAYmH06gGf87au38 kFnopgW8Yzc4c0sIZoN/X+A/ITwkrsLNabchbbfPzAZ4KZN9ubjcgJfU6cTzCi6mBT LqIlfmjSyuj2AMU4vOyTQnQtkwuKglHkdOYSRrZclC+vCHVdqXAnlTMD3ah0r5hhj6 TTmZrLiQBoAliKqqEvCE550q9qGq7sSk7U+ZheH/+qIDe8b6IfRP+ZPsDyDgg2bIVH aflwsP21urj+tagvAOfukk5cCb8ZjKEk8lH7l7iS5dDTXcDK2ELHU+6/9IVwrhBqqU hZwaekU4cLqBA== In-Reply-To: <87y1tgqhmc.fsf@localhost> Received-SPF: pass client-ip=209.250.245.214; envelope-from=miha@kamnitnik.top; helo=kamnitnik.top X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.001, PDS_OTHER_BAD_TLD=1.999, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297989 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Ihor Radchenko writes: > Hello, > > I am trying to figure out how to programmatically capture output of a > multi-line bash script in comint buffer. > > Consider: > > [yantar92:/tmp] $=20 >> if true >> then >> echo "hello" >> fi > hello > > Each line is submitted to shell via comint-send-input and, AFAIK, the > result can be collected using `comint-output-filter-functions'. > > I expect the `comint-output-filter-functions' to be called on "hello" > line. However, it does not seem to be the case. Empty "" corresponding > to "> " PS2 prompts upon sending incomplete script lines are also > passed. > > Is it possible to distinguish the actual script output, empty lines in > the actual script output, and the incomplete prompts? You could prepend your multiline command with a dummy 'echo multiline_starts_here' command have your 'comint-output-filter-functions' discard output that arrives before "multiline_starts_here". Or maybe inject something like 'oldps=3D$PS2; PS2=3D""' before the command and 'PS2=3D$oldps' after the command. But whether this works could depend on the shell, some shells might have something like $PS3 or $RPS1, for example. You could also accept-process-output after sending each individual line separately, but this depends on the user not customizing PS2=3D"" in his bashrc. As far as Emacs is concerned, PS1/PS2 prompts and non-prompt process output is all data, read from a single file descriptor. I don't think it's possible to distinguish them reliably without the above tricks or some other heuristics. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmNNx+4THG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZPxC4D/wJNxR7Vstn9G1QtuMjb/WFIiWYbVFa l/P6QfoKzqp5X2GdeXF/wdmMLBKfrhV4IFTbap/d7WuN+5yVkO93/sBOjaOYSj2P HdIjzxkwk+zW5o1ZuQ1DpJwET1Ce0DDiibck7ChObKqfA6cKrmg5mnLIp3yQE1oN 7y8um2iyQleCGPWQsY0UgCLN4i0EeAHbZY0L8mgMrbBTs4GdrSBe57g8tIxiK/hA EBl0airp8hZb3d6e42Tnc0ORQDMbnbZnwoTzzgHqPZxZirSf8Bro2YA0LQiGHLOK Qk8+nGfn7+V1YCtDtwpG0KZt2509Xs3P93dx85thZVqdEdYaVFazYvr6lxCQPMst waOMIH+wx31hMYgIgLPVNjqHDEpcCoOpgQ34NkxbbyMwsWf7115WsYuxKtKGwhDk MAYJ8C2po0lT816OE1sLmtLjNQorAVC37MTtYUtEXPGdtNLSfqE/bE/WB5srvDxC pAdHHnwVg6vs7sQSqH2AH11lEiwgEXAhq3qLhocYNwRMk/isXcJv0LsCPRP/S6yE MGft8cASdm4wDb3NtdIrFex6qOAnhzuhQte5deLqiDcPkzGOWERfS+sV9/rSDVQV 65m0DPVEEJP659qzPlwM9V7fid/sLngsXZquGW210WBEVlAllnLMi5RL8gCDkRsb N9jK5hZu1m/SXg== =VLD7 -----END PGP SIGNATURE----- --=-=-=--