-
Notifications
You must be signed in to change notification settings - Fork 425
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
Bad encoding on default picocli.CommandLine#getOut and picocli.CommandLine#getErr #1320
Comments
Interesting, I was not aware of this. Will you be able to provide a pull request for this? |
I assume that your source code (that contains the |
My code doesn't contain special characters but deal with .csv files which might contain some. For the question mark, I don't know 😕 It might come from the font used by the terminal. |
I've done some research and the question mark is the result of the use of an unmappable-character. When an unmappable-character is encountered, the default behavior of Here is some code to test: String problem = "[abcµ]";
CharsetEncoder cp437 = Charset.forName("cp437").newEncoder();
System.out.println(cp437.canEncode(problem)); // returns false
cp437.onUnmappableCharacter(CodingErrorAction.REPLACE);
cp437.encode(CharBuffer.wrap(problem)); // doesn't throw exception
cp437.onUnmappableCharacter(CodingErrorAction.REPORT);
cp437.encode(CharBuffer.wrap(problem)); // throws exception |
Thanks for the PR! |
…stdout.encoding` and `sun.stderr.encoding`
This reverts commit 33bce97.
…of `sun.stdout.encoding` and `sun.stderr.encoding`" This reverts commit f82fe75.
This reverts commit 33bce97.
…of `sun.stdout.encoding` and `sun.stderr.encoding`" This reverts commit f82fe75.
Depending on your console settings, the default
PrintWriter
ofpicocli.CommandLine#getOut
may use a bad encoding.Picocli code:
This code creates a
PrintWriter
usingCharset.defaultCharset()
which can be different from the current console encoding.A possible solution would be to use
Charset.forName(System.getProperty("sun.stdout.encoding"))
.See https://github.com/keerath/openjdk-8-source/blob/5f6e9d42a9f6b6736100c9c6f43f5f5ea1570cfb/jdk/src/share/classes/java/lang/System.java#L1189
Here is a code to reproduce (Windows 10, command prompt, encoding cp437):
The text was updated successfully, but these errors were encountered: