Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pipe input to a python program #40792

Closed
rivest mannequin opened this issue Aug 20, 2004 · 7 comments
Closed

Can't pipe input to a python program #40792

rivest mannequin opened this issue Aug 20, 2004 · 7 comments
Assignees

Comments

@rivest
Copy link
Mannequin

rivest mannequin commented Aug 20, 2004

BPO 1012692
Nosy @tim-one, @loewis
Files
  • python_pipe_bug.txt: More details...
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/tim-one'
    closed_at = <Date 2004-08-22.07:18:16.000>
    created_at = <Date 2004-08-20.05:31:29.000>
    labels = ['OS-windows']
    title = "Can't pipe input to a python program"
    updated_at = <Date 2004-08-22.07:18:16.000>
    user = 'https://bugs.python.org/rivest'

    bugs.python.org fields:

    activity = <Date 2004-08-22.07:18:16.000>
    actor = 'tim.peters'
    assignee = 'tim.peters'
    closed = True
    closed_date = None
    closer = None
    components = ['Windows']
    creation = <Date 2004-08-20.05:31:29.000>
    creator = 'rivest'
    dependencies = []
    files = ['1373']
    hgrepos = []
    issue_num = 1012692
    keywords = []
    message_count = 7.0
    messages = ['22145', '22146', '22147', '22148', '22149', '22150', '22151']
    nosy_count = 3.0
    nosy_names = ['tim.peters', 'loewis', 'rivest']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1012692'
    versions = []

    @rivest
    Copy link
    Mannequin Author

    rivest mannequin commented Aug 20, 2004

    Details in attached file. Basically, I want to be
    able (in Windows) to pipe input as in:
    type spam.txt | eggs.py
    so that eggs can read the file spam.txt. But I am
    getting an Errno 9: Bad file descriptor error message.

    Thanks.

        Cheers,
        Ron Rivest
        rivest@mit.edu 
    

    [Please reply to rivest@mit.edu as well...]

    @rivest rivest mannequin closed this as completed Aug 20, 2004
    @rivest rivest mannequin assigned tim-one Aug 20, 2004
    @rivest rivest mannequin added the OS-windows label Aug 20, 2004
    @rivest rivest mannequin closed this as completed Aug 20, 2004
    @rivest rivest mannequin assigned tim-one Aug 20, 2004
    @rivest rivest mannequin added the OS-windows label Aug 20, 2004
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Aug 21, 2004

    Logged In: YES
    user_id=21627

    What shell is this in? I cannot reproduce this in a cmd.exe
    window. However, that you report the version as "Windows 5.1
    (Build 2600)" and not "Microsoft Windows XP [Version
    5.1.2600]" (as ver.exe does), and that you use just ">" as
    the prompt suggests you might be using a different command
    interpreter.

    Can you please add

    print sys.stdin.fileno()

    into the script? On my system, it gives "0".

    @rivest
    Copy link
    Mannequin Author

    rivest mannequin commented Aug 21, 2004

    Logged In: YES
    user_id=1090045

    If I print out sys.stdin.fileno(), I get -1 .
    Ver.exe outputs: Microsoft Windows XP [Version 5.1.2600]
    This is indeed the standard command interpreter; I set the
    prompt envinronment variable to output just ">".

    Thanks...

        Ron Rivest
    

    @tim-one
    Copy link
    Member

    tim-one commented Aug 21, 2004

    Logged In: YES
    user_id=31435

    I see the same on my Win XP Pro SP1 box, but I expected
    to. The problem is in cmd.exe (the native XP shell), and both
    MS shells (command.com and cmd.exe) have had multiple
    bugs with I/O redirection forever. This somewhat confused
    MS KB article describes the current state for cmd.exe
    systems, in part incorrectly:

    "STDIN/STDOUT Redirection May Not Work If Started from a
    File Association"

    http://support.microsoft.com/default.aspx?kbid=321788

    It works fine if you change the "eggs.py" part of your
    command line to "python eggs.py", where "python" is some
    string that resolves to your Python executable, or even to
    a .bat script that runs python.exe explicitly. For example, I
    have a py.bat on my PATH, containing just

    \python23\python.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

    and then

    type spam.txt | py eggs.py
    

    works fine. The point is that it doesn't work if Python gets
    started via .py *association*; any other way of getting
    Python started works fine.

    Since this has nothing to do with Python (same thing if you
    use, e.g., Perl), I'm closing this as 3rd Party, Won't Fix.

    BTW, the KB article above claims the problem was fixed in XP
    SP1. It does indeed appear to have been fixed for stdout
    redirection, but not for stdin.

    You could also use Cygwin on Windows, whose default bash
    shell has sane behavior in this respect.

    Martin, it's sure curious that it works for you! My ver output
    is also "Microsoft Windows XP [Version 5.1.2600]". Is that
    enough to distinguish Home from Pro versions? I have Pro
    here. What do you have? Is yours a German flavor of XP?

    I'll note that I get one more line of output than Ron reported
    (the first output line, about "a nonexistent pipe"):

    C:\Code\python\PCbuild>type tcap.txt | eggs.py
    The process tried to write to a nonexistent pipe.
    Traceback (most recent call last):
      File "C:\Code\python\PCbuild\eggs.py", line 4, in ?
        text = sys.stdin.read()
    IOError: [Errno 9] Bad file descriptor

    @rivest
    Copy link
    Mannequin Author

    rivest mannequin commented Aug 21, 2004

    Logged In: YES
    user_id=1090045

    Thanks to tim_one!

    Your analysis of the situation does seem correct, and
    your proposed fix (to pipe to "python eggs.py" rather than
    just to "eggs.py") works fine!

    I agree that the "3rd Pary; Won't Fix" designation is
    appropriate.

    Thanks again!

        Cheers,
        Ronald L. Rivest
    

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Aug 22, 2004

    Logged In: YES
    user_id=21627

    It worked for me since I didn't reproduce Ron's actions
    precisely :-(
    I automatically did

    type spam.txt | \python23\python.exe eggs.py

    since on that system, I had deleted the .py extension, so
    merely typing "eggs.py" wouldn't have worked, anyway...

    @tim-one
    Copy link
    Member

    tim-one commented Aug 22, 2004

    Logged In: YES
    user_id=31435

    Ah, that would explain it <wink>. It's still curious that the KB
    article specifically lists the bug as being in XP Pro, but
    doesn't mention XP home. Then again, there are several
    inaccuracies in that article ...

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant