all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Daiki Ueno <ueno@gnu.org>
Cc: wk@gnupg.org, emacs-devel@gnu.org
Subject: Re: pipe
Date: Tue, 17 Mar 2015 10:47:20 +0200	[thread overview]
Message-ID: <8361a0yprb.fsf@gnu.org> (raw)
In-Reply-To: <m338549jhc.fsf-ueno@gnu.org>

> From: Daiki Ueno <ueno@gnu.org>
> Cc: Werner Koch <wk@gnupg.org>,  emacs-devel@gnu.org
> Date: Tue, 17 Mar 2015 16:22:07 +0900
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> > But that means it would be impossible to invoke gpg from a shell that
> >> > can redirect handles beyond the first 3, like some decent port of
> >> > Bash, is that correct?  Or is that where the wrapper comes into play,
> >> 
> >> I don't know about a native Bash port to Windows.  Using Cygwin with
> >> native Windows programs is problematic has you probably know.
> >
> > I was thinking about MSYS Bash.  But any port of Bash should do, as
> > redirecting file handles for a sub-process is trivial.
> 
> Thanks for all the information.  I'm almost lost :-)

Welcome to the club ;-)

> Are the following assumptions correct?
> 
> - A subprocess on Windows is able to access a handle passed as an
>   external representation from the parent, as described in the first
>   example of:
>   https://msdn.microsoft.com/en-us/library/aa298531%28v=vs.60%29.aspx

Yes.  (But what is passed on the command line is not the HANDLE, it's
the file descriptor; the corresponding HANDLE is passed behind the
scenes, AFAIK, using the undocumented fields of the STARTUPINFO
structure.)

Please note that the magic that passes the inherited HANDLEs to the
child process is in the Windows C runtime, as part of the
implementation of the "spawn*" family of functions.  Emacs bypasses
"spawn*" and has its own implementation of 'spawnve', which doesn't
include the equivalent code.  So if we want Emacs to be able to use
pipes that use file descriptors beyond the 3 standard ones, we will
have to add the code which passes the corresponding HANDLEs.

> - Some shells maintain the mappings between file descriptors and
>   handles, and if Emacs runs a shell program with a redirection to
>   non-standard file descriptors, it might not work as expected

I don't understand what you are saying here.  Please elaborate, or
give an example.

What I meant is this:

  . Werner says that the --status-fd etc. options need to have HANDLEs
    as arguments on Windows, not file descriptors.

  . Invoking gpg from Bash with the likes of ">&5" doesn't provide a
    way of finding out the HANDLE that corresponds to the file
    descriptor 5, and so I'm unsure how can the gpg command line be
    constructed using HANDLE values instead of descriptors.

The mapping between file descriptors and the corresponding HANDLEs is
maintained by the C runtime for each process, and there are 2 library
functions to get the HANDLE given a descriptor, and a descriptor for a
handle.  But I'm not aware of a way of getting these mappings from the
shell's prompt.

> - Emacs uses Gnulib's pipe2 implementation around _pipe on native
>   Windows and the returned file descriptors are actually a handle

No, Emacs uses its own implementation of pipe2 (see w32.c), which
returns file descriptors.  (And I think you are mistaken about the
Gnulib implementation: it also returns file descriptors, not HANDLEs,
because the '_pipe' call returns descriptors.)

> If all of those are correct, perhaps we could just mention the fact that
> the child ends of a pipe process is a handle on Windows?

Not all of those are correct, but I'm unsure what the implications
are, see above.

> In any case, supporting stderr could be a starting point, as it seems to
> be a long-standing request:
> https://lists.gnu.org/archive/html/emacs-devel/2004-04/msg01051.html
> and it wouldn't involve a portability issue.

Redirecting the child's stderr is already supported on Windows, so
this is only a matter of having the higher layers DTRT.



  reply	other threads:[~2015-03-17  8:47 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-13  9:01 pipe Daiki Ueno
2015-03-13 10:59 ` pipe Eli Zaretskii
2015-03-13 12:29   ` pipe Daiki Ueno
2015-03-13 20:08     ` pipe Werner Koch
2015-03-14  8:54       ` pipe Eli Zaretskii
2015-03-14 11:51         ` pipe Werner Koch
2015-03-14 13:42           ` pipe Eli Zaretskii
2015-03-14 19:28             ` pipe Werner Koch
2015-03-14 20:34               ` pipe Eli Zaretskii
2015-03-17  7:22                 ` pipe Daiki Ueno
2015-03-17  8:47                   ` Eli Zaretskii [this message]
2015-03-13 12:45 ` pipe Stefan Monnier
2015-03-13 13:10   ` pipe Daiki Ueno
2015-03-16  5:42     ` [PATCH] Generalize start-process with keyword args Daiki Ueno
2015-03-16 13:34       ` Stefan Monnier
2015-03-17  2:16         ` Daiki Ueno
2015-03-17  3:13           ` Stefan Monnier
2015-03-17  3:39             ` Daiki Ueno
2015-03-17 15:35               ` Stefan Monnier
2015-03-17 15:42                 ` Eli Zaretskii
2015-03-17 18:08                   ` Stefan Monnier
2015-03-17 18:19                     ` Eli Zaretskii
2015-03-17 21:36                       ` Stefan Monnier
2015-03-18  3:47                         ` Eli Zaretskii
2015-03-18  6:17                           ` Daiki Ueno
2015-03-18  7:37                             ` [PATCH] Add facility to collect stderr of async subprocess Daiki Ueno
2015-03-18 16:25                               ` Eli Zaretskii
2015-03-31  7:27                                 ` Daiki Ueno
2015-03-31 12:55                                   ` Eli Zaretskii
2015-04-08  0:21                                     ` Daiki Ueno
2015-04-08  0:47                                       ` Paul Eggert
2015-04-08  2:55                                         ` Daiki Ueno
2015-04-08  6:17                                           ` Eli Zaretskii
2015-04-08  6:20                                             ` Eli Zaretskii
2015-04-08  7:05                                             ` Daiki Ueno
2015-04-10 23:11                                               ` Daiki Ueno
2015-04-18 10:55                                                 ` Ted Zlatanov
2016-10-05  4:33                                                 ` Tino Calancha
2016-10-05  6:54                                                   ` Eli Zaretskii
2016-10-05  7:10                                                     ` Tino Calancha
2016-10-05  7:37                                                       ` Eli Zaretskii
2016-10-05 16:22                                                         ` John Wiegley
2016-10-06  3:13                                                           ` Tino Calancha
2016-10-06  6:54                                                             ` Eli Zaretskii
2016-10-06  7:25                                                               ` Tino Calancha
2016-10-06  7:55                                                                 ` Eli Zaretskii
2016-10-06  8:37                                                                   ` Tino Calancha
2016-10-06  8:53                                                                     ` Eli Zaretskii
2016-10-06  9:13                                                                       ` Tino Calancha
2016-10-06  9:25                                                                         ` Michael Albinus
2016-10-06  9:45                                                                           ` Tino Calancha
2016-10-06  9:22                                                                     ` Michael Albinus
2016-10-06  7:15                                                         ` Philipp Stephani
2016-10-06  7:42                                                           ` Eli Zaretskii
2016-10-05  8:46                                                     ` Alain Schneble
2016-10-05  9:15                                                       ` Tino Calancha
2016-10-05 11:20                                                     ` Michael Albinus
2016-10-05 17:24                                                       ` Eli Zaretskii
2016-10-06  7:27                                                         ` Michael Albinus
2015-04-08  5:56                                       ` Eli Zaretskii
2015-03-18 13:03                             ` [PATCH] Generalize start-process with keyword args Stefan Monnier
2015-03-18 16:34                               ` Eli Zaretskii
2015-03-19  7:36                               ` Daiki Ueno
2015-03-19 13:32                                 ` Stefan Monnier
2015-03-23  7:36                                   ` Daiki Ueno
2015-03-18 16:23                             ` Eli Zaretskii
2015-03-18 18:57                               ` Stefan Monnier
2015-03-18 19:13                                 ` Eli Zaretskii
2015-03-17  7:50           ` Eli Zaretskii
2015-03-16 19:12       ` Andy Moreton
2015-03-16 19:40         ` Eli Zaretskii
2015-03-16 22:27           ` Andy Moreton
2015-03-17  0:39             ` Stefan Monnier
2015-03-17  7:15             ` Eli Zaretskii
2015-03-17 20:55               ` Andy Moreton
2015-03-17 21:15                 ` Eli Zaretskii
2015-03-17 22:04                   ` Andy Moreton
2015-03-19 16:34                     ` Eli Zaretskii
2015-03-19 23:22                       ` Andy Moreton
2015-03-20 14:03                         ` Stefan Monnier
2015-03-17 21:42                 ` Stefan Monnier
2015-03-13 14:54   ` pipe Eli Zaretskii
2015-03-13 15:28     ` pipe Daniel Colascione
2015-03-13 15:40       ` pipe Eli Zaretskii

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=8361a0yprb.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=ueno@gnu.org \
    --cc=wk@gnupg.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.