[Bug] Unicode is not supported when using LINQPad 6 Util.Cmd

For this code:

Util.Cmd("echo 你好");

The output is:

���

Expected result:

你好
  • Environment info:
    Windows 10.0.19042.685
    .NET Core 5.0.1
    LINQPad 6.12.2

  • Note: works fine in LINQPad 5.44.0 but messy in LINQPad 6.12.2:

Comments

  • JoeAlbahari
    edited January 2021

    This fails for me in both LINQPad 5 and 6.

    I'm not sure whether it's possible to fix this without adding an argument to Util.Cmd to specify an encoding. LINQPad uses cmd.exe /c to execute shell commands such as 'echo'. And as far as I can see, cmd.exe doesn't have an option to force UTF-8. It has an option for UTF-16 (the /u switch), but while /u would support the scenario above, it would fail if the command called a program that wrote UTF-8 to stdout.

    Note that this problem will not occur if you call Util.Cmd with an executable rather than a shell command.

  • I guess this is the solution - I'll add an overload to Util.Cmd that accepts an encoding. Then you can pass in Encoding.Unicode (to override the default of Encoding.UTF8).