Skip to content

readProcess_ garbles non-ASCII output on failure #86

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

Closed
tomjaguarpaw opened this issue Apr 8, 2025 · 0 comments · Fixed by #87
Closed

readProcess_ garbles non-ASCII output on failure #86

tomjaguarpaw opened this issue Apr 8, 2025 · 0 comments · Fixed by #87

Comments

@tomjaguarpaw
Copy link
Collaborator

First consider runProcess_, which behaves well. It inherits stdin and stdout and therefore avoids interfering in any encoding decisions. As long as the subprocess output encoding matches the terminal encoding all is good:

ghci> runProcess_ (shell "echo привет;echo 😑 1>&2 ; exit 1")
привет
😑
*** Exception: Received ExitFailure 1 when running
Shell command: echo привет;echo 😑 1>&2 ; exit 1

But readProcess_ does not behave well. On failure, it puts stdin and stdout into an ExitCodeException. When it comes to call show or displayException it must choose an encoding to use, but it does not know which it should choose! Currently it uses decode :: ByteString -> String, which is probably the worst of all worlds:

ghci> readProcess_ (shell "echo привет;echo 😑 1>&2 ; exit 1")
*** Exception: Received ExitFailure 1 when running
Shell command: echo привет;echo 😑 1>&2 ; exit 1
Standard output:

пÑивеÑ
Standard error:

ð

The output is completely garbled, and this is really bad for anyone working with non-ASCII.


Thanks to @9999years for bringing this to my attention in #83 (comment).

tomjaguarpaw added a commit to tomjaguarpaw/typed-process that referenced this issue Apr 8, 2025
tomjaguarpaw added a commit to tomjaguarpaw/typed-process that referenced this issue Apr 8, 2025
tomjaguarpaw added a commit to tomjaguarpaw/typed-process that referenced this issue Apr 8, 2025
9999years added a commit to 9999years/typed-process that referenced this issue Apr 8, 2025
Partial fix for fpco#86. This isn't perfect (for retrocomputing you may want
another character encoding) but improves the behavior in many
circumstances.
9999years added a commit to 9999years/typed-process that referenced this issue Apr 8, 2025
Partial fix for fpco#86. This isn't perfect (for retrocomputing you may want
another character encoding) but improves the behavior in many
circumstances.
9999years added a commit to 9999years/typed-process that referenced this issue Apr 8, 2025
Partial fix for fpco#86. This isn't perfect (for retrocomputing you may want
another character encoding) but improves the behavior in many
circumstances.
tomjaguarpaw added a commit to tomjaguarpaw/typed-process that referenced this issue Apr 8, 2025
Closes fpco#86

Thanks to @9999years for the legwork on this change
tomjaguarpaw added a commit to tomjaguarpaw/typed-process that referenced this issue Apr 12, 2025
Closes fpco#86

Thanks to @9999years for the legwork on this change
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 a pull request may close this issue.

1 participant