-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
Elixir and Erlang/OTP versions
Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit:ns]
Elixir 1.18.0 (compiled with Erlang/OTP 27)
Operating system
Linux
Current behavior
Using mix cmd
to run programs that print out non-ASCII characters results in incorrectly encoded output. This behaviour is since #14027.
To reproduce, run mix cmd echo ✔
. The output will be â
instead of ✔
.
Expected behavior
This bug is due to Mix.Shell.IO.cmd/2
using IO.binwrite
instead of IO.write
even on non-Windows systems.
iex(1)> Mix.Shell.cmd("echo ✔", [], &IO.write/1)
✔
0
iex(2)> Mix.Shell.cmd("echo ✔", [], &IO.binwrite/1)
â
0
I think the following change should fix this (if this looks good happy to make a PR):
def cmd(command, opts \\ []) do
print_app? = Keyword.get(opts, :print_app, true)
Mix.Shell.cmd(command, opts, fn data ->
if print_app?, do: print_app()
case :os.type() do
{:win32, _} ->
# Due to encoding of shell command on Windows,
# let's write the data as is
IO.binwrite(data)
_ -> IO.write(data)
end
end)
end
Metadata
Metadata
Assignees
Labels
No labels