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.

classification
Title: subprocess.py fails on Windows when there is no console
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: astrand Nosy List: astrand, blais
Priority: normal Keywords:

Created on 2005-11-16 22:59 by blais, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py blais, 2005-11-17 13:39 example script
Messages (3)
msg26894 - (view) Author: Martin Blais (blais) * (Python committer) Date: 2005-11-16 22:59
Under Windows XP, using Python 2.4.2, calling a
subprocess from "subprocess.py" from a script that does
not have a console, with stdin=None (the default) fails.

Since there is a check for stdin=stdout=stderr=None
that just returns, to exhibit this problem you need to
at least set stdout=PIPE (just to get it to run past
the check for that special case).

The problem is that in _get_handles(), l581-582:

            if stdin == None:
                p2cread = GetStdHandle(STD_INPUT_HANDLE)


GetStdHandle returns None if there is no console.  This
is rather nasty bugger of a bug, since I suppose it
breaks most GUI applications that start without the
console (i.e. most) and that eventually invoke
subprocesses and capture their output.  I'm surprised
to find this.


To reproduce the problem, do this:

1. save the attached script to C:/temp/bug.py and
C:/temp/bug.pyw
2. create two shortcuts on your desktop to invoke those
scripts
3. open a shell and tail C:/temp/out.log


For bug.py, the log file should display:

2005-11-16 17:38:11,661 INFO 0


For bug.pyw (no console), the log file should show the
following exception:

2005-11-16 17:38:13,084 ERROR Traceback (most recent
call last):

  File "C:\Temp\bug.pyw", line 20, in ?
    out = call(['C:/Cygwin/bin/ls.exe'], stdout=PIPE)
#, stderr=PIPE)
  File "C:\Python24\lib\subprocess.py", line 412, in call
    return Popen(*args, **kwargs).wait()
  File "C:\Python24\lib\subprocess.py", line 533, in
__init__
    (p2cread, p2cwrite,
  File "C:\Python24\lib\subprocess.py", line 593, in
_get_handles
    p2cread = self._make_inheritable(p2cread)
  File "C:\Python24\lib\subprocess.py", line 634, in
_make_inheritable
    DUPLICATE_SAME_ACCESS)
TypeError: an integer is required

This is the bug.


Note: in this test program, I'm invoking Cygwin's
ls.exe.  Feel free to change it
msg26895 - (view) Author: Martin Blais (blais) * (Python committer) Date: 2005-11-17 13:41
Logged In: YES 
user_id=10996

Here is an example of a workaround:

    p = Popen(ps2pdf,
              stdin=PIPE, stdout=PIPE, stderr=PIPE,
              cwd=tempfile.gettempdir())
    p.stdin.close() # FIXME: we need to specify and close
stdin explicitly
                    # because of a bug I found and reported
in subprocess.py
                    # when the program is launched without a
console, see SF bug
                    # tracker for the Python project for
details.  When the bug
                    # gets fixed we should be able to remove
this.


Basically I just specify stdin=PIPE and close it by hand.
msg26896 - (view) Author: Peter Åstrand (astrand) * (Python committer) Date: 2007-01-22 19:27
Duplicate of 1124861. 
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42601
2005-11-16 22:59:08blaiscreate