-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
How to setup "ProcessStartInfo.StandardOutputEncoding" #63
Comments
Depending on the execution model you're using, there should be overloads, for example: // Treat both stdout and stderr as UTF8-encoded text streams
var result = await Cli.Wrap("path/to/exe")
.WithArguments("--foo bar")
.ExecuteBufferedAsync(Encoding.UTF8);
// Treat stdout as ASCII-encoded and stderr as UTF8-encoded
var result = await Cli.Wrap("path/to/exe")
.WithArguments("--foo bar")
.ExecuteBufferedAsync(Encoding.ASCII, Encoding.UTF8); |
There's no way to "inform" the application about the encoding. This is basically the same thing as setting |
Unfortunately it is not the same. Usually an appliction asks the kernel which is the ConsoleOutput Encoding. This is done with the function: UINT WINAPI GetConsoleOutputCP(void); In my Environment this is code page 850. If you print something which simply does not exits in your code page - these characters are replaced with something like "?". Have a look at System/ConsolePal.Windows. You can find the call at line 112. This function must return 65001 to produce UTF-8. |
As far as I know, it just defaults to On the side of |
Unfortunately I believe you are right, sorry. Currently I create a CLI object / Command with the path to the exe. I could instead call cmd.exe and execute chcp 65001 followed by the real exe. But that seems to be not really nice. The app I want to start is a dotnet exe. Take for example such a simple app: using System;
namespace Tests
{
public static class UnicodeSample
{
public static void Main()
{
System.Console.WriteLine("Some text with non - ascii: Российская Федерация!");
}
}
} How can I call it with CliWrap? |
I'm not sure how to re-implement I would assume that if in your app you do If you don't control the target executable, and it writes unicode characters without actually changing the encoding to unicode, I'm not sure there's anything that can be done, short of re-implementing |
Thanks for your answer. As far as I understand CliWrap does it via redirection. To inpret the received data it uses these encoding-settings -> totaly fine. If Unicode handling on windows is really a mess. |
Yeah. The only way to work around it (besides changing
That seems to make sense. But it has to be done by the target executable. Do you control the actual target executable you're trying to run with |
I can't change the code of the "slave-apps". I "solved" it now with the following code: var cli = Cli.Wrap("cmd").WithArguments($"/c chcp 65001 > null && {appPath} {arguments}") |
I also looked into WinAPI, there seems to be no way of changing the character page of another process, only the calling one. So it appears the |
Anyway, thanks for your support. Perhaps it is something for the docs (especially for the ExecuteBufferedAsync method with Encoding parameters). |
I would like to start a CSharp app via cmd which prints UTF-8 Text.
To work correctly I need to execute chcp 65001 first or start it with a non ANS OutputEncoding.
This would be possible by setting StandardOutputEncoding of the class ProcessStartInfo.
The construction of this class is unfortunately handled in a private method. Could you make these internals somehow available? Best would be something like an "OnAdjustProcessStartInfo" event.
I have seen that you have an overload ExecuteAsync which affects the interpretation of the binary output... But it does not "inform" the application about that encoding.
The text was updated successfully, but these errors were encountered: