zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Redirect a specific file descriptor to a pipe?
Date: Fri, 10 Mar 2017 18:24:30 -0800	[thread overview]
Message-ID: <170310182430.ZM17517@torch.brasslantern.com> (raw)
In-Reply-To: <CADgEyUu9Ds5kNMA-uLa0Fo4KHw6AKfC4r3dDqBJ--4rcPU9Lvw@mail.gmail.com>

On Mar 10,  4:32pm, Nathan Dorfman wrote:
}
} I still think it might be useful to be able to pipe any fd, not just
} stdout, but I don't know if I can contrive a great example.

It depends on what your intentions are.  The definition of a pipeline
in shell syntax is that the standard output of the left side connects
to the standard input of the right side.  So if you want to use a pipe,
you have to make the right thing *be* stdout, regardless of which other
descriptor it might have started out to be.

So when I talk about intentions: Where do you expect stdout of the left
side to go if some other descriptor is feeding the pipe?

} Perhaps we
} can't redirect stdout because it's a curses program that needs direct
} terminal access, but we want to do something like this:
} 
} strace -o /dev/fd/3 mutt 3>XXX
} 
} Where instead of XXX, we want to send fd 3 to |xz or |ssh?

In that example you want "mutt" to remain the foreground process (it
can't share the terminal with xz or ssh).  So you have to run xz in
the background.  That is what process substitution is for:

    strace -o /dev/fd/3 mutt 3>>(xz)

This puts xz in the background with its input connected to fd 3 and
it's output still connected to the terminal, while mutt stays in the
foreground with stdin + stdout unchanged.

It's up to you (or to xz) to make sure the subshell doesn't attempt to
spew something onto the terminal mutt is using.

On Mar 11,  1:17am, Mikael Magnusson wrote:
}
} whatever_command 5> >(pipe command here) 7> >(some other pipe here)
}
} but now that i'm testing it, it seems to not complete when it should

It's not hung, >(some other pipe here) is in the background so its
output has probably been printed below the prompt.  Try

strace -o /dev/fd/7 =true 7> >(cat); wait

which will wait for >(cat) to finish before printing another prompt [it
is a relatively recent change to zsh that you can "wait" for process
substitution background jobs].


      parent reply	other threads:[~2017-03-11  2:24 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
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 [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=170310182430.ZM17517@torch.brasslantern.com \
    --to=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).