Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Redirect a specific file descriptor to a pipe?



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



Messages sorted by: Reverse Date, Date, Thread, Author