oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.12k stars 176 forks source link

ExternalTool method ConsoleRun(Action<string> onConsoleOut) pass invalid unicode strings to onConsoleOut #303

Closed DarthSidius closed 6 years ago

DarthSidius commented 6 years ago

ExternalTool method ConsoleRun(Action onConsoleOut) pass invalid unicode strings to onConsoleOut:

"S\0e\0D\0e\0b\0u\0g\0P\0r\0i\0v\0i\0l\0e\0g\0e\0 \0:\0 \0\u001e\u0004B\u0004:\u00040\u00047\u00040\u0004=\u0004>\u0004 \02\u0004 \04\u0004>\u0004A\u0004B\u0004C\u0004?\u00045\u0004.\0" ...

DarthSidius commented 6 years ago

This code produce valid output:

using( var p = new Process() ) { p.StartInfo.FileName = "subinacl.exe"; p.StartInfo.Arguments = $"/service MsSqlServer /grant={new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null).Translate(typeof(NTAccount))}=T"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.StandardOutputEncoding = Encoding.Unicode; // !!! p.Start(); var output = p.StandardOutput.ReadToEnd(); p.WaitForExit(15000); }

oleg-shilo commented 6 years ago

Excellent point. I completely overlooked it.

Done:

new ExternalTool
{
     ExePath = insigniaPath,
     Arguments = "-ab \"{1}\" \"{0}\" -o \"{0}\"".FormatWith(bootstrapperFileToSign, enginePath),
     Encoding = Encoding.Unicode
};

I checked with my other products and I always use Encoding.UTF8. I made it default for ExternalTool.Encoding.

Is there any reason you opted to Encoding.Unicode? If none, can you please verify that Encoding.UTF8 works for your conditions?

Thank you.

DarthSidius commented 6 years ago

Windows 10 Pro Russian: UTF8 - https://github.com/oleg-shilo/wixsharp/issues/303#issue-298131621 Unicode - valid strings

ExternalTool.Encoding - in the documentation there is no description

oleg-shilo commented 6 years ago

..in the documentation there is no description

Correct. The solution as not been released publicly yet. I have only committed the code.

Still, I want you to elaborate on the original question. Can you please verify that Encoding.UTF8 works for your conditions?

DarthSidius commented 6 years ago

UTF8 does not work Unicode works

oleg-shilo commented 6 years ago

Thank you.

oleg-shilo commented 6 years ago

OK after further testing I found that Encoding.Unicode is not a good choice of default Encoding as it is conflicts with with the majority of the CLI tools on an English Win.

I am trying to find a compromise, so can you please test your environment with Encoding = Encoding.Default. Sorry but I just don't have Russian configured Windows to test it.

Thank you.