Issue #4 invalid


created an issue

Is there any solution for using pipes without having to run 'py'? For example, "[command] | py" works fine, but "[command] |" fails because sys.stdin is None.

Simple test script: {{{


import sys

print type(sys.stdin)

if not sys.stdin.isatty(): print }}}

My guess is that instead of cmd.exe creating the process and setting up the input pipe, the route through the registry calls CreateProcess with a STARTUPINFO in which hStdInput doesn't reference the pipe. But I'm far from an expert on such matters.

Comments (6)

  1. Vinay Sajip

    It works for me - See this screenshot.

    Screenshot of py working with a pipe

    This was cmd.exe on Windows 7 (64-bit). Your problem may be appearing on an older version of Windows and/or cmd.exe, but IMO it's not anything to do with the launcher's operation.

    I get the same results for

    echo Hello, world! | showver


    echo Hello, world! | py

  2. eryksun reporter

    In Python 2, sys.stdin exists but the fileno is -2. In Python 3 sys.stdin is None. Repeated trials also cause cmd to report "The process tried to write to a nonexistent pipe" just before running the script. The is on Windows XP, service pack 3. Apparently, as Vinay's screenshot shows, the problem is fixed in newer versions. I doubt anything can be done, but it's good to have some info about it, as there are still a lot of XP systems around.

  3. Vinay Sajip

    Possibly relevant:

    Though that refers to Windows 2000, it may be that the problem still occurs in XP (although the post does say for Windows XP that the problem should be fixed in "the latest service pack for Windows XP", which would be SP3). It may be worth checking if a hotfix is available. It's also worth checking that InheritConsoleHandles key mentioned in the Microsoft post, to confirm that it's present and set to the expected value - however, I believe that the Microsoft fix only applies to output handles, but not to sys.stdin. This was Tim Peters' comment in 2004:

  4. eryksun reporter

    The system has service pack 3, but the registry setting wasn't enabled. The following policy setting fixed the problem:



  5. Log in to comment