2

I am trying to launch a Java program in C# which arguments include Chinese.

ProcessStartInfo StartInfo = New ProcessStartInfo(Javaw);
StartInfo.Arguments = LaunchArgument; //-cp "D:\特殊字符\文件名.jar" com.something.test --arg "特殊字符"
NewProcess.StartInfo = StartInfo;
NewProcess.Start();

This is normal if Windows's code page is GBK (Chinese), but if the code page is changed to UTF-8, Java will throw java.lang.ClassNotFoundException: com.something.test

In my examination, Java does not seem to be able to properly read Chinese characters in -cp when the system code page is UTF-8.

I'v seen Passing command line unicode argument to Java code, but there doesn't seem to be a solution using C#.

Modifying the system code page is fine, but requiring users to adjust system settings before using the software is silly...


What I've tried:

  • Adding -Dfile.encoding=GBK or -Dfile.encoding=UTF-8 to the argument.

  • Use * to replace Chinese like this, but that doesn't work either.

    -cp "D:\*\*.jar" com.something.test

  • Use a .bat file and change the code page with the CHCP command at the beginning of it.

chcp 936
"C:\Program Files\Java\jdk-17.0.3.1\bin\java.exe" -cp "D:\特殊字符\文件名.jar" com.something.test --arg "特殊字符"

Also due to the needs of users, there is no way to avoid these Chinese characters in parameters. Sorry.

LTCat
  • 21
  • 3
  • Interesting. Out of interest, what does `dir D:\ /ad/x` show you? (Do that in a new cmd.exe - i.e. with its normal code page) – g00se Jun 21 '22 at 10:31

0 Answers0