Open choongzhanhong opened 1 year ago
I don't think there is a straightforward way since you are redirecting terminal to file. You have some control on the terminal by setting the flag, not sure how to ensure redirected text also follows the encoding. If you are printing directly to the file, you can make Java do it by setting the encoding, but redirecting, not sure 😕
I have cloned your project and ran the command sh runtest.sh
on my M1 laptop and received the following in my ACTUAL.txt.
██████╗ █████╗ ██████╗ █████╗
██╔══██╗██╔══██╗██╔══██╗██╔══██╗
██████╔╝███████║██████╔╝███████║
██╔═══╝ ██╔══██║██╔═══╝ ██╔══██║
██║ ██║ ██║██║ ██║ ██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
================================
Hello! I'm PAPA, your Personal Assistant, Personal Angel.
What can I do for you? Type 'help' for a list of commands.
================================
>
Can you list down the steps to reproduce the issue?
I used the included batch file and added the flag so line 10 looks like this: javac -cp ..\src\main\java -encoding ISO-8859-1 -Xlint:none -d ..\bin ..\src\main\java\*.java
I got the output in ACTUAL.txt. Changed nothing else. If I run it in IntelliJ, I get to see my desired logo (Like in your output). However, running it in cmd or redirecting to another file leads to the weird glyphs.
I tried changing the encoding in the code itself, such as with PrintStream out = new PrintStream(System.out, true, "UTF-8");
Didn't work, but I didnt spend much time digging into the issue as of now.
I think I can just change the logo to feature characters that are more available on all platforms, it's purely cosmetic.
I had tried again and I received the ???
in the IntelliJ's in-built terminal but when I run the programme on VSC terminal and macbook's own terminal, I am able to print out the output as shown in the ACTUAL.txt
.
Can you try checking whether you are able to do the same? Run the java file on the intellij terminal, then other terminal such as VSC's or your computer's? If it is, then it is probably the issue to do with IntelliJ's terminal and not the encoding.
Image 1: IntelliJ Terminal Image 2: VSC Terminal
On IntelliJ Terminal:
"C:\Program Files\Java\jdk-19\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.3.1\lib\idea_rt.jar=63575:C:\Program Files\JetBrains\IntelliJ IDEA 2022.3.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\Documents\CS2113Projects\iP\out\production\iP Duke
██████╗ █████╗ ██████╗ █████╗
██╔══██╗██╔══██╗██╔══██╗██╔══██╗
██████╔╝███████║██████╔╝███████║
██╔═══╝ ██╔══██║██╔═══╝ ██╔══██║
██║ ██║ ██║██║ ██║ ██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
================================
Hello! I'm PAPA, your Personal Assistant, Personal Angel.
What can I do for you? Type 'help' for a list of commands.
================================
>
in cmd (Windows)
??????? ?????? ??????? ??????
????????????????????????????????
????????????????????????????????
??????? ??????????????? ????????
??? ??? ?????? ??? ???
??? ??? ?????? ??? ???
================================
Hello! I'm PAPA, your Personal Assistant, Personal Angel.
What can I do for you? Type 'help' for a list of commands.
================================
>
Looking at the IntelliJ output, seems like there is some automatic encoding on my end such that it works in the IntelliJ Console.
Hi, all. I recently ran into an issue with running the automated testing batch file, with the error relating to encoding a string I had printed. For context, I named my version of Duke "PAPA" and gave it a new logo.
I had trouble compiling and running (Although it runs fine in IntelliJ), and it turns out to be due to the uncommon characters being used. After looking up on stackoverflow, it seems adding the flag
-encoding ISO-8859-1
allows the files to compile and the batch file to run.Now, here's what it outputs on the ACTUAL.txt output file:
Now, it seems a minor issue since it's not something I need to do testing on, but is there a proper way to address this issue and to make sure it outputs correctly onto the .txt file?