-
Notifications
You must be signed in to change notification settings - Fork 269
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
The Atom script package requires script execution screen encoding in Java #1166
Comments
You need to handle unicode strings properly. Here is a issue about python #701 |
It is not the programming language encoding, but the encoding of the console. |
We can't change the encoding of console. it runs through cmd or bash (for java) with default system encoding |
That might be the problem : console is not in default system encoding, as when the tests are executed in the terminal, they do work. So if anyone has any insight as how to correct atom, it is welcome. Note that I have the same issue in sublimetext, so this really is a core issue as to how they execute shell commands. |
It looks like atom-script on Windows uses cp1252 (Windows 1252) encoding by default instead of utf-8. As a work-around you can specify the encoding as utf-8 in your code for the system out and error streams:
|
@dbolton ✨ thanks 👍 , it is very helpful despite this is the temporary measure of code. Because the author @rgbkrk saids on #214 that he couldn't afford to manage this, I have to use this so far.
BEFORE :
AFTER :
|
I solved this problem by adding an environment variable
You can press Ctrl+Alt+Shift+O to add it. |
@github-mi cool! |
@dbolton Bull's eye! Thank you for your very good solution! |
@github-mi very nice solution! |
Mind the workaround to detach the stdout and stderr might interfer with python's logging module, for me it throws an exception that the underlying buffer has been detached. |
@github-mi |
@MaciekZar You setup up an actual environment variable in your windows system. |
PYTHONIOENCODING=utf-8 is OK for python but what to do if I use javascript? |
Atom-script invokes cmd.exe underneath and does not care about its codepage. As a result, cmd.exe is invoked with its system default codepage and atom-script is treated them as utf-8 but they do not match each other. Typical commands like java.exe and javac.exe output its messages in cmd.exe codepage (for example, in Japanese systems, it's cp932/Shift-JIS) so, as a result, in the atom-script tab it would display garbled characters. If we would provide "process.env.JAVA_TOOL_OPTIONS="-Dfile.encoding=utf8"' in init.coffee, most of the problem would be gone, as javac.exe outputs warning messages in utf8, it treats its source codes in utf8 encoding and java.exe also outputs its standard output in utf8. There is a remaining problem, that original Java program might assume system's default file.encoding (in Japanese system, its cp932/Shift-JIS, again) but, in this environment, its would be changed into utf8. If, only if, the software writes some text files under and out of the atom-script execution environment, these two will produce incompatible output text files. (btw, Packages -> Script -> Configure Script >> providing 'JAVA_TOOL_OPTIONS="-Dfile.encoding=utf8"' in "Environment Variables:" would produce messages like:
which means that this options cannot handle quoted equals sign properly, and this should be addressed as well, I suppose.) There is one more difficult point. Windows system (at least, Japanese edition) would sometimes assume utf8 text files having BOM at the beginning. (For example, Excel would not accept utf8 csv files if they don't have BOM, while it would accept Shift-JIS csv's without any problems.) So, this strategy, using all encoding default as utf8, will sometimes create serious bugs. I have tried to go alternative way by putting following lines into init.coffee,
but, this could not change javac.exe's warning messages put in shift-jis, so it did not work. (Plus, I could not find ways to change javac.exe's warning messages encoding with its command-line options.) Another way to solve this is, change cmd.exe default to codepage 65001 (unicode) but, it would require editing registry and changing whole system default would be too much and overkill. To solve this problem, it is recommended to modify atom-script to use current codepage value of cmd.exe to display its output, or, maybe modify it to do "chcp 65001" at the initialization of the cmd.exe. I am totally new to this so I cannot point out exact code to change, and I would like to apology, but, I hope it would add something to the project. |
🎉 This issue has been resolved in version 3.31.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fix in #2421 only fixed python-encoding and won't fix original issue like java.exe/javac.exe encoding mismatch in build results tab. I have just updated to 3.31.3, tested and am seeing still such garbled characters displayed. |
The code for the Java runner is here. Any contribution to fix the issue for Java is greatly appreciated. I spent a long time trying to fix this, but since I am not a Java developer I don't know how I can fix this issue without it breaking other things. atom-script/lib/grammars/java.js Lines 22 to 29 in 443bf81
Here is the commit that I made and reverted later:
|
Thanks for indicating the spot. I will try reading codes, but as I have said, I am not familiar with the product, while I am a Java developer, so it may take time. |
Quick fix for the issue atom-community#1166, Java build in non-English editions of Window will result garbled message, stdout and stderr displayed. This fix would have further issue: if user's final target deployment would have different encodings from all-UTF-8 setup, (such as "normal" Windows cmd.exe, they normally have ANSI encodings for average users) so testing and evaluating might become more difficult.
looks like required options are removed from merge, and previous behaviors happens again now.... I can resubmit fix and it would work with Windows, but, I will check Linux later |
Co-authored-by: weather-tracker <[email protected]> Co-authored-by: Amin Yahyaabadi <[email protected]> * Adding back '-J-Dfile.encoding=UTF-8' for javac so its warning messages are printed in UTF-8 as well as its source files are treated as UTF-8 encoding. * Adding back -Xlint for reporting detailed warning messages for compilers * removing quotation marks around file.encoding and UTF-8 for java command, since java command does not understand quotation marks when it is not removed by the shell (cmd.exe won't interpret that) update for issue #1166
windows cmd
atom script execution screen
The text was updated successfully, but these errors were encountered: