There are quite large number of reasons this can fail...
The first thing I would do is try to make it work in oplrun.
When you choose utf-8 as the encoding in the IDE, it only means that the content of the file is utf-8 encoded, nothing more.
The OPL runtime is not aware at all of this encoding, so when it creates an ILOG Script string (which is certainly internally stored as utf-16) it has to know what encoding to use to make the conversion.
When you want to write to a file, it also needs an encoding to go from utf-16 to the on-disk format.
It looks like there is an enviroment variable OPL_NATIVE_LOCALE that might be used for this (just guessing...)
oplrun has a -locale setting, as shown here :
C:\Users\FredericDelhoume\eclipse-workspace\smallpt\target>oplrun -v -locale toto "c:\Program Files\IBM\ILOG\CPLEX_Studio_Beta201\opl\examples\opl\BasketballScheduling\acc.mod"
Setting LOCALE failed: bad locale name
Interesting names on Windows include: us_us.1252
chs_chn.936 simplified chinese, GBK
.936 simplified chinese, GBK
cht_twn.950 traditional chinese, Big5
.950 traditional chinese, Big5
jpn_jpn.932 japanese, Shift-JIS
.932 japanese, Shift-JIS
deu_deu.1252
fra_fra.1252
### exception bad locale name
I do not know if this can be used to specify utf-8 (Windows before version 10 could not have an utf-8 locale).
Writing string in the IDE console is much more complicated as it requires conversion from/to Java, and internally scripting is used for serialization, there is a OPL_CHARSET variable that may be used for this.
For example for Japanese, you may launch the IDE with -Xlocale .932 -Xcharset Shift_JIS that will be converted to OPL_NATIVE_LOCALE and OPL_CHARSET.
This is a very complicated topic and beyond my knowledge unfortunalety...
------------------------------
Frederic Delhoume
------------------------------
Original Message:
Sent: Thu October 22, 2020 09:14 AM
From: Andrew Bullock
Subject: Writing UTF-8 from ILOG Script
Alex
An update. Eddie tried it on his recently built UK machine running 12.10 and set to UTF-8 in the IDE settings. He gets the same in the scripting log:
XXX æ±‰è¯ XXX â"€ â"‚ â"Œ â"� â"" â"˜ • · XXX
Any suggestions?
Thanks
Andrew
------------------------------
Andrew Bullock
Original Message:
Sent: Wed October 21, 2020 10:16 AM
From: Andrew Bullock
Subject: Writing UTF-8 from ILOG Script
Alex
Many thanks for looking into this further. So it seems your scripting log works whilst mine doesn't. I'm not sure why. If you have any further ideas then let me know, else I will abandon the whole issue and just use a text output file, which while not as good is workable.
The only possible reasons I can think of are:
- I'm only using 12.8
- I've got some weird UK setup on my machine which stops UTF-8 working properly
Andrew
------------------------------
Andrew Bullock
Original Message:
Sent: Wed October 21, 2020 04:18 AM
From: ALEX FLEISCHER
Subject: Writing UTF-8 from ILOG Script
Hi,
with the right encoding I get the right display in the scripting log:
execute
{
var s="été";
var f=new IloOplOutputFile("essai.txt");
f.writeln(s);
f.close();
writeln(s);
}
and
I get
été
in the scripting log
regards
------------------------------
ALEX FLEISCHER
Original Message:
Sent: Tue October 20, 2020 08:50 AM
From: Andrew Bullock
Subject: Writing UTF-8 from ILOG Script
This one picture should explain the essence of the remaining problem:
------------------------------
Andrew Bullock
Original Message:
Sent: Tue October 20, 2020 07:11 AM
From: Andrew Bullock
Subject: Writing UTF-8 from ILOG Script
Alex
The characters now display OK in the IDE editor with the UTF-8 preference change. It's just that they don't display OK in the IDE scripting log. I tried restarting the IDE but that made no difference.
Maybe I didn't understand your last point on globalisation, but the text displays OK in the IDE editor so I assume that my OS supports it.
The font in both the editor and the scripting log is the same default Courier New so that shouldn't be an issue.
I've looked at more general posts on using UTF-8 in Eclipse and there seem to be many possible courses of action to make it work properly.
Any other ideas on how to make the Scripting Log display the characters? Does it display them for you?
Thanks
------------------------------
Andrew Bullock
Original Message:
Sent: Tue October 20, 2020 05:04 AM
From: ALEX FLEISCHER
Subject: Writing UTF-8 from ILOG Script
Hi,
in documentation
------------------------------
ALEX FLEISCHER
Original Message:
Sent: Tue October 20, 2020 04:49 AM
From: Andrew Bullock
Subject: Writing UTF-8 from ILOG Script
Alex
Thanks for this. For those in English the switch to UTF-8 is here:
------------------------------
Andrew Bullock
Original Message:
Sent: Tue October 20, 2020 04:25 AM
From: ALEX FLEISCHER
Subject: Writing UTF-8 from ILOG Script
Hi,
at least in OPL
execute
{
var s="汉语";
var f=new IloOplOutputFile("essai.txt");
f.writeln(s);
f.close();
}
works fine
and builds essai.txt
汉语
And in the CPLEX IDE I used UTF8
------------------------------
ALEX FLEISCHER
Original Message:
Sent: Mon October 19, 2020 04:14 PM
From: Andrew Bullock
Subject: Writing UTF-8 from ILOG Script
Chris
I have no code for this. I need to know whether it is even possible and how to do it. There is nothing in the manual and the existing links point to DeveloperWorks and these posts haven't been migrated to this forum so they are no longer visible.
Can you say whether writing multi-byte characters to files and/or the scripting log is possible in ILOG Script.
Thanks
Andrew
------------------------------
Andrew Bullock
Original Message:
Sent: Mon October 19, 2020 12:21 PM
From: Christiane Bracchi
Subject: Writing UTF-8 from ILOG Script
Hello Andrew,
Did you try it?
Could you show us your code in order to allow us to check what happens?
Regards,
Chris.
------------------------------
Christiane Bracchi
Original Message:
Sent: Fri October 16, 2020 03:58 AM
From: Andrew Bullock
Subject: Writing UTF-8 from ILOG Script
Hi there
I'm trying to write out UTF-8 / multi-byte characters from within ILOG Script, ideally both through IloOplOutputFile and to the scripting log. I found some old posts on this issue but the links are now dead.
Any ideas whether / how this is possible?
Thanks
Andrew
------------------------------
Andrew Bullock
------------------------------
#DecisionOptimization