zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Nathan Dorfman <na@rtfm.net>, zsh-users@zsh.org
Subject: Re: Redirect a specific file descriptor to a pipe?
Date: Fri, 10 Mar 2017 17:22:19 +0000	[thread overview]
Message-ID: <20170310172219.GA4206@chaz.gmail.com> (raw)
In-Reply-To: <170309180417.ZM14034__34042.4779606566$1489111700$gmane$org@torch.brasslantern.com>

2017-03-09 18:04:17 -0800, Bart Schaefer:
> On Mar 9,  5:21pm, Nathan Dorfman wrote:
> }
> } strace -o /dev/fd/3 ./a.out > out.log 2> err.log 3>XXX
> } 
> } Instead of file XXX, I'd like to send fd 3 to |less. Is it possible?
> 
> You just need this:
> 
> strace -o /dev/fd/3 ./a.out > out.log 2> err.log 3>&1 | less
[...]

No quite. There are two issues here, one zsh specific:

cmd > file | cmd2

In zsh (with multios on by default) is special and redirects
stdout both to file and cmd2 (and the 3>&1 would also redirect
fd 3 to both).

In Bourne-like syntax, you'd also need to change the order:

strace -o /dev/fd/3 ./a.out 3>&1 > out.log 2> err.log | less

That is, redirect the fd 3 to the same thing as fd 1 at the time
that fd 1 was the pipe, *and then* redirect fd 1 to out.log.

In zsh, to avoid the multios effect, you can do:

{strace -o /dev/fd/3 ./a.out 3>&1 > out.log 2> err.log} | less

or disable multios (set +o multios).

-- 
Stephane


  parent reply	other threads:[~2017-03-10 17:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-10  0:21 Nathan Dorfman
2017-03-10  2:04 ` Bart Schaefer
     [not found] ` <170309180417.ZM14034__34042.4779606566$1489111700$gmane$org@torch.brasslantern.com>
2017-03-10 17:22   ` Stephane Chazelas [this message]
2017-03-10 18:51     ` Bart Schaefer
2017-03-10 23:32       ` Nathan Dorfman
2017-03-11  0:17         ` Mikael Magnusson
2017-03-11  2:24         ` Bart Schaefer

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=20170310172219.GA4206@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=na@rtfm.net \
    --cc=schaefer@brasslantern.com \
    --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).