zsh-users
 help / color / mirror / code / Atom feed
* Redirect &2 into a command - HowTo
@ 1997-10-24 14:36 Helmut Jarausch
  1997-10-24 14:57 ` Andrew Main
  1997-10-24 15:00 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Helmut Jarausch @ 1997-10-24 14:36 UTC (permalink / raw)
  To: zsh-users

Hi!

Sorry if this is a FAQ (I didn't find it there).

Is there any possibility to redirect STDERR to a command like 'xless'
without redirecting  STDOUT as well?

Thanks for any hints,
Helmut.






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Redirect &2 into a command - HowTo
  1997-10-24 14:36 Redirect &2 into a command - HowTo Helmut Jarausch
@ 1997-10-24 14:57 ` Andrew Main
  1997-10-24 15:00 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Main @ 1997-10-24 14:57 UTC (permalink / raw)
  To: Helmut Jarausch; +Cc: zsh-users

Helmut Jarausch wrote:
>Is there any possibility to redirect STDERR to a command like 'xless'
>without redirecting  STDOUT as well?

The simplest way is

foo 2>>(xless)

but this executes the command asynchronously, which may not be what
you want.  To do it synchronously:

{ { foo 1>&3 } 2>&1 | xless } 3>&1

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Redirect &2 into a command - HowTo
  1997-10-24 14:36 Redirect &2 into a command - HowTo Helmut Jarausch
  1997-10-24 14:57 ` Andrew Main
@ 1997-10-24 15:00 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1997-10-24 15:00 UTC (permalink / raw)
  To: Zsh users list

Helmut Jarausch wrote:
> Sorry if this is a FAQ (I didn't find it there).

You may find it in the general shell FAQs; it'll work in any proper
shell (i.e. not csh, tcsh).

> Is there any possibility to redirect STDERR to a command like 'xless'
> without redirecting  STDOUT as well?

The trick is to use a spare FD to swap the first two.

mycmd 3>&1 1>&2 2>&3 3>&- | xless

which means 1) open a new fd 3 to stdout (the pipe) 2) redirect stdout
to where stderr is 3) now move stderr to 3, which is the original
stdout 4) to be tidy, close the spare fd, though in this case that's
not actually necessary (I won't bore you).

One important extra which isn't in anyone else's FAQ:  in zsh, you need
to `setopt nomultios', since a `multio' will interpret the `1>&2' as
saying you want stdout to go to both the old stderr *and* the pipe,
which in this case you don't.  (Do we need an option `pipemultios', which
is off by default?)

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-10-24 15:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-24 14:36 Redirect &2 into a command - HowTo Helmut Jarausch
1997-10-24 14:57 ` Andrew Main
1997-10-24 15:00 ` Peter Stephenson

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).