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

General Windows stdout redirection not working #56571

Closed
CrouZ mannequin opened this issue Jun 19, 2011 · 5 comments
Closed

General Windows stdout redirection not working #56571

CrouZ mannequin opened this issue Jun 19, 2011 · 5 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@CrouZ
Copy link
Mannequin

CrouZ mannequin commented Jun 19, 2011

BPO 12362
Nosy @amauryfa, @bitdancer
Superseder
  • bpo-9390: Error in sys.excepthook on windows when redirecting output of the script
  • 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 = None
    closed_at = <Date 2011-06-19.14:38:53.091>
    created_at = <Date 2011-06-19.11:54:28.528>
    labels = ['type-bug', 'OS-windows']
    title = 'General Windows stdout redirection not working'
    updated_at = <Date 2011-06-19.15:59:51.548>
    user = 'https://bugs.python.org/CrouZ'

    bugs.python.org fields:

    activity = <Date 2011-06-19.15:59:51.548>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-06-19.14:38:53.091>
    closer = 'r.david.murray'
    components = ['Windows']
    creation = <Date 2011-06-19.11:54:28.528>
    creator = 'CrouZ'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 12362
    keywords = []
    message_count = 5.0
    messages = ['138626', '138630', '138634', '138635', '138638']
    nosy_count = 3.0
    nosy_names = ['amaury.forgeotdarc', 'r.david.murray', 'CrouZ']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '9390'
    type = 'behavior'
    url = 'https://bugs.python.org/issue12362'
    versions = ['Python 3.1', 'Python 2.7']

    @CrouZ
    Copy link
    Mannequin Author

    CrouZ mannequin commented Jun 19, 2011

    Steps to repeat:

    • Create the script foo.py consisting of the line: print("foo")
    • Run: foo.py > bar

    Behavior:
    2.7.2: The file bar is created but empty. Prints the following message on exit:

    close failed in file object destructor:
    sys.excepthook is missing
    lost sys.stderr

    3.1.4: The file bar is created but empty. No printouts indicating that something went wrong.

    Expected behavior:
    All: The file bar has the content foo.

    Additional information:
    sys.stdout, and probably also sys.stderr, do not appear to be set up properly.
    2.7.2: stdout is set to a file but performing any operations on it throws the exception: IOError: [Errno 9] Bad file descriptor
    3.1.4: stdout is set to None

    Workaround:
    All: python foo.py > bar

    Used software:
    Windows 7 Ultimate SP1 x64 (6.1.7601)
    Python 2.7.2 and 3.1.4 installed with the msi-installer including Registering Extensions.

    @CrouZ CrouZ mannequin added type-crash A hard crash of the interpreter, possibly with a core dump OS-windows type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Jun 19, 2011
    @bitdancer
    Copy link
    Member

    The file association for .py is pythonw, which does exactly as you say, intentionally, so as to avoid problems with windows when running a GUI application. My understanding is that this caters to the most common use case on Windows: double clicking a .py file launching a Python GUI application. When running a python script in the console, use 'python', as in your example (or manually change your file association).

    @amauryfa
    Copy link
    Member

    "The file association for .py is pythonw"
    Really? http://docs.python.org/using/windows.html#executing-scripts

    @amauryfa
    Copy link
    Member

    IMO the cause is actually the same as the one for bpo-9390, i.e. a bug in the Windows console.

    @bitdancer
    Copy link
    Member

    Ah, I should have known better than to rely on a memory instead of checking, since I don't use Windows much. My apologies.

    @bitdancer bitdancer removed the invalid label Jun 19, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants