This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author trentm
Recipients trentm, twhitema
Date 2008-09-19.05:19:16
SpamBayes Score 4.79483e-12
Marked as misclassified No
Message-id <>
The failure is in the DuplicateHandle call that subprocess makes on, in
this case, the stdin handle (as returned by
`GetStdHandle(STD_INPUT_HANDLE)`) call earlier.

Two cases here:

1. When this is run in a subsystem:windows process (like PythonWin or
IDLE) that is launched from Windows Explorer (e.g. from a Start Menu
shortcut or Desktop shortcut) then `GetStdHandle(STD_INPUT_HANDLE)`
returns None. 

> If an application does not have associated standard handles,
> such as a service running on an interactive desktop, and has
> not redirected them, the return value is NULL.

In this case you *don't* get the error that Todd described, because the
code path taken in then use CreatePipe for the `p2cread`
variable on which `DuplicateHandle` is called.

2. However, when the subsystem:windows process is launched from the
cmd.exe shell the `GetStdHandle` call returns a value -- in Todd's and
my testing, the value 3.

The code path in then calls `DuplicateHandle` on this in
`Popen._make_inheritable`. This fails with traceback Todd posted.

My *guess* at what the problem is stems from this comment in the MSDN
docs on console handles:

> A process can use the DuplicateHandle function to create a 
> duplicate console handle that has different access or 
> inheritability from the original handle. Note, however,
> that a process can create a duplicate console handle only
> for its own use. This differs from other handle types (such
> as file, pipe, or mutex objects), for which DuplicateHandle
> can create a duplicate that is valid for a different process.

My guess is that the stdin handle (3) is inherited from the shell
(cmd.exe) and attempting to `DuplicateHandle` on it violates the clause
that you can on dupe a console handle of your own. I'm not sure of that

Anyone else have more light to shed on this?

If this is the case I'm not sure what a possible or good solution could
be for subprocess.
Date User Action Args
2008-09-19 05:19:22trentmsetrecipients: + trentm, twhitema
2008-09-19 05:19:22trentmsetmessageid: <>
2008-09-19 05:19:21trentmlinkissue3905 messages
2008-09-19 05:19:18trentmcreate