Skip to content

readProcess_ garbles non-ASCII output on failure #86

Closed
@tomjaguarpaw

Description

@tomjaguarpaw

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions