zsh-users
 help / color / mirror / code / Atom feed
* pipes and redirection
@ 1996-10-29 19:22 Gerald Skerbitz
  1996-10-29 21:39 ` Zefram
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gerald Skerbitz @ 1996-10-29 19:22 UTC (permalink / raw)
  To: zsh-users


I've been trying desparately to do something with the shell and failing.

The goal is to get stdout to go to a file, and stderr to be piped to
another program.

If I do this:

(print -u2 This is stderr;print This is stdout) 2>&1 1>test

Then the file "test" contains the string "This is stdout"
and "This is stderr" is printed to the terminal.

So, assuming that the pipe (|) should send the stdout (file descriptor 1) on
to the program, I tried this:

(print -u2 This is stderr;print This is stdout) 2>&1 1>test | less

which brought up less, with _both_ strings displayed.
So, clearly, the | is picking up both streams.

Is there a way to cleanly do what I want it to do?

--
Gerry
Gerald Skerbitz <gsker@med.umn.edu> U of MN Med School Admin 6-5379
Home St. Paul,Ramsey County,Minnesota, USA



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

* Re: pipes and redirection
  1996-10-29 19:22 pipes and redirection Gerald Skerbitz
@ 1996-10-29 21:39 ` Zefram
  1996-10-29 22:08 ` Geoff Wing
  1996-10-30  9:07 ` Peter Stephenson
  2 siblings, 0 replies; 6+ messages in thread
From: Zefram @ 1996-10-29 21:39 UTC (permalink / raw)
  To: gsker; +Cc: zsh-users

>The goal is to get stdout to go to a file, and stderr to be piped to
>another program.

(print -u2 This is stderr;print This is stdout) 1>test 2>>(tr a-z A-Z > test2)

Unfortunately the command inside >() gets executed asynchronously, but
that suffices in many cases.  (Out of interest, why is it
asynchronous?  I've always thought that synchronous execution, as with
normal pipelines, would be more natural and usually more useful.)

-zefram


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

* Re: pipes and redirection
  1996-10-29 19:22 pipes and redirection Gerald Skerbitz
  1996-10-29 21:39 ` Zefram
@ 1996-10-29 22:08 ` Geoff Wing
  1996-10-30  9:07 ` Peter Stephenson
  2 siblings, 0 replies; 6+ messages in thread
From: Geoff Wing @ 1996-10-29 22:08 UTC (permalink / raw)
  To: gsker; +Cc: zsh-users

Gerald Skerbitz wrote:
:I've been trying desparately to do something with the shell and failing.
:The goal is to get stdout to go to a file, and stderr to be piped to
:another program.
:If I do this:
:(print -u2 This is stderr;print This is stdout) 2>&1 1>test
:Then the file "test" contains the string "This is stdout"
:and "This is stderr" is printed to the terminal.
:
:So, assuming that the pipe (|) should send the stdout (file descriptor 1) on
:to the program, I tried this:
:(print -u2 This is stderr;print This is stdout) 2>&1 1>test | less
:which brought up less, with _both_ strings displayed.
:So, clearly, the | is picking up both streams.
:Is there a way to cleanly do what I want it to do?

You could always do:
coproc (print -u2 This is stderr;print This is stdout) 2>&p >test ; less <&p
-- 
Geoff Wing [gwing@primenet.com.au]     PrimeNet - Internet Consultancy
  Web   : http://www.primenet.com.au/  Phone    : +61-3-9818 2977
  Mobile: 0412 162 441		       Facsimile: +61-3-9819 3788


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

* Re: pipes and redirection
  1996-10-29 19:22 pipes and redirection Gerald Skerbitz
  1996-10-29 21:39 ` Zefram
  1996-10-29 22:08 ` Geoff Wing
@ 1996-10-30  9:07 ` Peter Stephenson
  1996-10-30 13:33   ` Gerald Skerbitz
  2 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 1996-10-30  9:07 UTC (permalink / raw)
  To: gsker, zsh-users

Gerald Skerbitz wrote:
> (print -u2 This is stderr;print This is stdout) 2>&1 1>test | less
> 
> which brought up less, with _both_ strings displayed.
> So, clearly, the | is picking up both streams.
> 
> Is there a way to cleanly do what I want it to do?

The correct answer, if you have a recent version of zsh, is
to `setopt nomultios' before trying the above.  Zsh's multio feature
is redirecting stdout both to test and to the pipe.  It's a little
counterintuitive here, as has been pointed out before.  The option
appeared some time mid 2.6beta.

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


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

* Re: pipes and redirection
  1996-10-30  9:07 ` Peter Stephenson
@ 1996-10-30 13:33   ` Gerald Skerbitz
  1996-10-30 14:08     ` Zefram
  0 siblings, 1 reply; 6+ messages in thread
From: Gerald Skerbitz @ 1996-10-30 13:33 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

On Wed, 30 Oct 1996, Peter Stephenson wrote:
> The correct answer, if you have a recent version of zsh, is
3.0.0

> to `setopt nomultios' before trying the above.  Zsh's multio feature
> is redirecting stdout both to test and to the pipe.  It's a little
> counterintuitive here, as has been pointed out before.  The option
> appeared some time mid 2.6beta.

I considered that the problem was that I had `setopt multios', then I checked
by typing `setopt' and `multios' was NOT on the list, so I figured from that
that I DIDN'T have the multios feature turned on.  Then I tried `setopt
nomultios' as above and it worked.  Why did I have to set that explicitly? 

Thank you very much for your help!
--
Gerry
Gerald Skerbitz <gsker@med.umn.edu> U of MN Med School Admin 6-5379
Home St. Paul,Ramsey County,Minnesota, USA


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

* Re: pipes and redirection
  1996-10-30 13:33   ` Gerald Skerbitz
@ 1996-10-30 14:08     ` Zefram
  0 siblings, 0 replies; 6+ messages in thread
From: Zefram @ 1996-10-30 14:08 UTC (permalink / raw)
  To: gsker; +Cc: pws, zsh-users

>I considered that the problem was that I had `setopt multios', then I checked
>by typing `setopt' and `multios' was NOT on the list, so I figured from that
>that I DIDN'T have the multios feature turned on.

If you had types `unsetopt', then `nomultios' would have appeared.
`setopt' now lists those options set to a non-default state.

>                                                   Then I tried `setopt
>nomultios' as above and it worked.  Why did I have to set that explicitly? 

Because multios are available by default.  The facility to turn them
off was added relatively recently.

-zefram


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

end of thread, other threads:[~1996-10-30 14:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-29 19:22 pipes and redirection Gerald Skerbitz
1996-10-29 21:39 ` Zefram
1996-10-29 22:08 ` Geoff Wing
1996-10-30  9:07 ` Peter Stephenson
1996-10-30 13:33   ` Gerald Skerbitz
1996-10-30 14:08     ` Zefram

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