Groovy Modules

groovy cannot read Chinese character in command line parameter properly

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Native Launcher
  • Labels:
    None
  • Environment:
    windows XP sp3, java 1.6.0_14, groovy 1.6.3
    1.6.1 version of groovy eclipse plugin
  • Number of attachments :
    0

Description

I tried to get some file name from command line parameter, which have some Chinese characters. For example:

public class CNtest{
public static void main(def args){ println args }
}

then run with
groovy CNtest 白色城堡
will get following result
[°×?]
There is no difference if I put quote around the Chinese file name.

However, I believe previous version of groovy don't have this problem – maybe version before 1.6.2. Because I don't remember I met this problem before I upgrade groovy. I tried to install an older version groovy but it seemed that I have to uninstall current version first, so I didn't continue.

However, this script can get the parameter properly in Eclipse groovy plugin. I put the same Chinese file name into "run configuration" "program parameters", then I can get the proper result. I'm not sure if this is related to groovy 1.6.1 bundled with the plugin, or something related to eclipse handling parameters.

Activity

Hide
blackdrag blackdrag added a comment -

there are many possible reasons for this not working. I just tested 1.6.3 on my ubuntu box here and it did not have any problem from the command line. Could you try out the command line as well please?

Show
blackdrag blackdrag added a comment - there are many possible reasons for this not working. I just tested 1.6.3 on my ubuntu box here and it did not have any problem from the command line. Could you try out the command line as well please?
Hide
draco added a comment -

I was running this in command line of windows.

groovy CNtest 白色城堡

This should be platform related, so it's possible ubuntu don't have this problem.

Show
draco added a comment - I was running this in command line of windows. groovy CNtest 白色城堡 This should be platform related, so it's possible ubuntu don't have this problem.
Hide
draco added a comment -

I downgraded to groovy 1.6.2 and the problem disapeared.

Show
draco added a comment - I downgraded to groovy 1.6.2 and the problem disapeared.
Hide
draco added a comment -

Thanks for Paul King's advice, I tried 1.6.3 again with groovy.bat. groovy.bat don't have this problem, so the problem is from the native launcher.

Show
draco added a comment - Thanks for Paul King's advice, I tried 1.6.3 again with groovy.bat. groovy.bat don't have this problem, so the problem is from the native launcher.
Hide
Antti Karanta added a comment -

The native launcher assumes strings are passed in as UTF-8, in which case they should be handled ok (using JNI NewStringUTF8 to convert them to Java strings).

However, I'm not sure how windows encodes the input strings. I'm so used to it being broken (with any program) with non-ascii with even scandinavian characters (هنِ) that I thought it just doesn't handle non-ascii at all.

I tried actively setting command prompt to understand utf-8 as instructed here: http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how

That only changed the displayed chars from ? to a weird symbol.

BTW, neither groovy.bat nor groovy.exe yield the correct output for scandinavian characters, e.g.

C:\>groovy.exe -e "println args[0]" هنِ
σΣ÷

C:\>groovy.bat -e "println args[0]" هنِ
σΣ÷

To get further with this issue I'd need to be able to reproduce it. How does one get windows command prompt to handle chinese characters? I tried copy pasting the example command line given above, but got just "????" in place of the chinese chars. Do I need to install some language pack?

Show
Antti Karanta added a comment - The native launcher assumes strings are passed in as UTF-8, in which case they should be handled ok (using JNI NewStringUTF8 to convert them to Java strings). However, I'm not sure how windows encodes the input strings. I'm so used to it being broken (with any program) with non-ascii with even scandinavian characters (هنِ) that I thought it just doesn't handle non-ascii at all. I tried actively setting command prompt to understand utf-8 as instructed here: http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how That only changed the displayed chars from ? to a weird symbol. BTW, neither groovy.bat nor groovy.exe yield the correct output for scandinavian characters, e.g. C:\>groovy.exe -e "println args[0]" هنِ σΣ÷ C:\>groovy.bat -e "println args[0]" هنِ σΣ÷ To get further with this issue I'd need to be able to reproduce it. How does one get windows command prompt to handle chinese characters? I tried copy pasting the example command line given above, but got just "????" in place of the chinese chars. Do I need to install some language pack?
Hide
draco added a comment -

I think the Chinese input methods came from MS windows can be switched on in command prompt. But I was using input method from other party, so I just copy and paste it into the command prompt.
To make your windows handle Chinese characters (even copy and paste), I think you need to do this(I assume your windows is windows XP):
Control panels -> language and zone settings
Language tab: I had the option "install files for east asia lanuage" under "additional language support" checked, but I don't know if your windows have this option.
Advanced tab: non-unicode program language: Chinese
Code page: check 20936 (GB2312) , 50227(Simplified Chinese), 52936, 54936, 936

If I remembered correctly, I used to make English version windows XP support Chinese characters after this adjustment.

Maybe this method can make your windows handle scandinavian characters better too if you choose appropriate code page?

Show
draco added a comment - I think the Chinese input methods came from MS windows can be switched on in command prompt. But I was using input method from other party, so I just copy and paste it into the command prompt. To make your windows handle Chinese characters (even copy and paste), I think you need to do this(I assume your windows is windows XP): Control panels -> language and zone settings Language tab: I had the option "install files for east asia lanuage" under "additional language support" checked, but I don't know if your windows have this option. Advanced tab: non-unicode program language: Chinese Code page: check 20936 (GB2312) , 50227(Simplified Chinese), 52936, 54936, 936 If I remembered correctly, I used to make English version windows XP support Chinese characters after this adjustment. Maybe this method can make your windows handle scandinavian characters better too if you choose appropriate code page?
Hide
Antti Karanta added a comment -

I dug around a bit and I now have a couple of ideas of how this could be fixed.

However, I was still unable to get scandinavian, let alone chinese, letters to work in windows command prompt. I executed all the steps described by draco (except that I added also scandinavian code pages and set default non-unicode app lang to Finnish instead of Chinese as I don't want my computer to go all Chinese on me) but that did not help with the Finnish or Chinese characters.

So Draco, would you be willing to help me out a little with this one? What I'd need you to do is to try out the solution candidates as I get them done. I can send you the executables via email. Or, if you are wary of running executables I send, I can send you the sources and you can compile them yourself. The latter option requires a little more setup on your part. How to set up compiling the native launcher is described on the native launcher wiki page:

http://groovy.codehaus.org/Native+Launcher#NativeLauncher-Compiling

Show
Antti Karanta added a comment - I dug around a bit and I now have a couple of ideas of how this could be fixed. However, I was still unable to get scandinavian, let alone chinese, letters to work in windows command prompt. I executed all the steps described by draco (except that I added also scandinavian code pages and set default non-unicode app lang to Finnish instead of Chinese as I don't want my computer to go all Chinese on me) but that did not help with the Finnish or Chinese characters. So Draco, would you be willing to help me out a little with this one? What I'd need you to do is to try out the solution candidates as I get them done. I can send you the executables via email. Or, if you are wary of running executables I send, I can send you the sources and you can compile them yourself. The latter option requires a little more setup on your part. How to set up compiling the native launcher is described on the native launcher wiki page: http://groovy.codehaus.org/Native+Launcher#NativeLauncher-Compiling
Hide
draco added a comment -

I'll be more than happy to test them for you. You can just send me the executables. My email is dracodoc at gmail.com.

Show
draco added a comment - I'll be more than happy to test them for you. You can just send me the executables. My email is dracodoc at gmail.com.
Hide
Antti Karanta added a comment -

Changed jstring construction to use String(byte[]) constructor (which uses the platform's default charset) instead of JNI function NewStringUTF.

Thanks a lot to draco for help in testing!

Show
Antti Karanta added a comment - Changed jstring construction to use String(byte[]) constructor (which uses the platform's default charset) instead of JNI function NewStringUTF. Thanks a lot to draco for help in testing!
Hide
draco added a comment -

This issue appeared again in groovy 1.6.5, jdk 1.6.0_16.
I tested same scenario, same result as in 1.6.3.

F:\>groovy CNtest 白色城堡
[°×?]

F:\>call groovy.bat CNtest 白色城堡
白色城堡

Show
draco added a comment - This issue appeared again in groovy 1.6.5, jdk 1.6.0_16. I tested same scenario, same result as in 1.6.3. F:\>groovy CNtest 白色城堡 [°×?] F:\>call groovy.bat CNtest 白色城堡 白色城堡
Hide
blackdrag blackdrag added a comment -

this issue was about the native launcher, there is not even yet a 1.6.5 with native launcher yet. So I assume you used the 1.6.3 native launcher and just updated the remaining part of groovy. That won't do in your case.

Show
blackdrag blackdrag added a comment - this issue was about the native launcher, there is not even yet a 1.6.5 with native launcher yet. So I assume you used the 1.6.3 native launcher and just updated the remaining part of groovy. That won't do in your case.
Hide
draco added a comment -

Sorry, I just found the 1.6.5 download today and was excited. I was assuming the windows installer for 1.6.5 installed a updated native launcher, looks like it didn't.
Mm, I should use the one Karanta sent me for test, which don't have the problem

Show
draco added a comment - Sorry, I just found the 1.6.5 download today and was excited. I was assuming the windows installer for 1.6.5 installed a updated native launcher, looks like it didn't. Mm, I should use the one Karanta sent me for test, which don't have the problem
Hide
draco added a comment -

The 1.6.5 windows installer don't have a newer version native launcher, so this is still the old problem and has been solved.

Show
draco added a comment - The 1.6.5 windows installer don't have a newer version native launcher, so this is still the old problem and has been solved.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: