From: Bart Schaefer <schaefer@brasslantern.com>
To: "chiasa.men" <chiasa.men@web.de>
Cc: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: gnu script and zsh: only log command output
Date: Fri, 13 May 2022 12:12:27 -0700 [thread overview]
Message-ID: <CAH+w=7aP1kN3Gpzpga41OG01GRwzPuFk+sbcXaSSHJ+-=JDmhA@mail.gmail.com> (raw)
In-Reply-To: <2282060.4c44sqeuZD@march>
On Thu, May 12, 2022 at 11:46 AM chiasa.men <chiasa.men@web.de> wrote:
>
> When I use "script --log-output o --log-input i" I am facing two problems:
>
> 1: The output log contains the actual input: e.g. ".]0;test@test: echo 5.5"
> (see below)
> 2: The prompts
This is going to happen because "script" has taken over the terminal
device and ZLE must necessarily write to that terminal to display the
prompts and to echo back your keystrokes as it maintains the "editor"
state. Everything that comes and goes to the terminal is potentially
captured by "script" and there's no way for you to see/interact with
it that bypasses that. You can try switching off ZLE if you can stand
to work that way, but I think you'd still get the prompts captured.
> I really just want the programs output logged - no prompts, no shell-related
> output.
>
> Is that possible?
It's a bit difficult in zsh up to 5.8.1 ... once 5.9 is released, you
should be able to do something like this:
autoload add-zsh-hook
exec {stdout}>&1 {stderr}>&2
preexec_outputs() {
exec 2>>|stderr.log 2>&$stderr
exec 1>>|stdout.log 1>&$stdout
}
precmd_outputs() {
exec 1>&$stdout 2>&$stderr
}
add-zsh-hook preexec preexec_outputs
add-zsh-hook precmd precmd_outputs
However, this won't capture output of interactive programs like "vim"
which will either fail or will re-open the terminal device directly
(printing an error message first, in the case of vim).
> So would there be a way to reliably filter the zsh-related output e.g. within
> the _my_read_function function?
Using preexec and precmd you could write markers to the output that
would indicate when ZLE becomes active (precmd) and when it finishes
(preexec). Your python script could then discard anything between
those two markers. You'd have to be very sure that those markers
would never appear in output you actually want captured.
prev parent reply other threads:[~2022-05-13 19:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 18:45 chiasa.men
2022-05-13 19:12 ` Bart Schaefer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7aP1kN3Gpzpga41OG01GRwzPuFk+sbcXaSSHJ+-=JDmhA@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=chiasa.men@web.de \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).