Skip to content

mpy-cross: Fix output to stdout on Windows. #17879

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dlech
Copy link
Contributor

@dlech dlech commented Aug 10, 2025

Summary

Set stdout to binary mode on Windows to avoid corruption of MPY output.

By default, Windows uses text mode for stdout which will convert any newline byte (\n) to a carriage return + newline (\r\n) pair. This can corrupt the MPY output if the MPY contains any 0x0A byte.

Testing

I didn't see a way to test this using our existing test framework. But I have made a test in the python-mpy-cross project I maintain.

Failing test before the fix: https://github.com/pybricks/python-mpy-cross/actions/runs/16865780805/job/47772458449#step:4:538

Passing test after the fix: https://github.com/pybricks/python-mpy-cross/actions/runs/16866365087/job/47773824320#step:4:863

Test source: https://github.com/pybricks/python-mpy-cross/blob/f376b412573a0c8c825abc300c5e36a716a85f98/tests/test_mpy_cross.py#L40-L50

Set stdout to binary mode on Windows to avoid corruption of MPY output.

By default, Windows uses text mode for stdout which will convert any
newline byte (\n) to a carriage return + newline (\r\n) pair. This can
corrupt the MPY output if the MPY contains any 0x0A byte.

Signed-off-by: David Lechner <david@pybricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant