From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21309 invoked by alias); 4 Oct 2014 18:18:01 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33351 Received: (qmail 22765 invoked from network); 4 Oct 2014 18:17:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <141004111755.ZM7181@torch.brasslantern.com> Date: Sat, 04 Oct 2014 11:17:55 -0700 In-reply-to: <87mw9bu94f.fsf@gmail.com> Comments: In reply to Christian Neukirchen "Re: piping question" (Oct 4, 5:50pm) References: <1412259225.3798.0@numa-i> <141003082330.ZM15100__40912.263657856$1412349949$gmane$org@torch.brasslantern.com> <87mw9bu94f.fsf@gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: piping question MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Oct 4, 5:50pm, Christian Neukirchen wrote: } Subject: Re: piping question } } Bart Schaefer writes: } } > On Oct 3, 4:42pm, Mikael Magnusson wrote: } > } } > } echo hi there | { xterm -e 'most <& 7' 7< <(cat) } } > } > I avoided that because I was concerned that some terminal emulators } > would close all the descriptors above 2 when launching the command. } } Unfortunately, all these hacks don't work with urxvt. If anyone has an } idea how to do it, I'd like to see. This appears to be a combination of two problems: (1) The name used by <(cat) is platform-specific. E.g., on Debian- based systems, it matches /proc/self/fd/<-> which means it is interpreted relative to the current process, and "most" is two levels removed from zsh. On some other systems it's a named pipe, which works independent of /proc/self/ and is why it was the first thing I suggested. (2) As I feared, rxvt closes all the descriptors except 0,1,2 which it opened, making /proc/self/fd/<3-> all return EOF. To avoid this, you have to hand-code /proc/$$/fd/ instead of allowing zsh to create the /self/ name. The exact path may vary by platform. Also because rxvt executes the -e argument list directly rather than going through a shell, you don't need/want to re-quote arguments, but you also can't redirect input. So this should do it (options to set geometry etc. may be added): xmost() { if [[ -t 0 ]] then rxvt -e most "$@" else local procself=/proc/self procself=${procself:A} # Resolve symlink to actual PID local stdin exec {stdin}<&0 rxvt -e most "$@" $procself/fd/$stdin exec {stdin}<&- fi } I don't know about "most" so I didn't attempt to get the options right, but for "less" you need to add the -f option to be able to read the fifo. Also note that if rxvt is put in the background, you need to avoid closing $stdin until after it finishes, so the best way to make this asynchronous is to add "&" after the "fi". -- Barton E. Schaefer