|
[Sponsors] |
Unicode and special characters issue in DesignManager |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 8, 2022, 02:29 |
Unicode and special characters issue in DesignManager
|
#1 | |||
Senior Member
Chaotic Water
Join Date: Jul 2012
Location: Elgrin Fau
Posts: 437
Rep Power: 18 |
Hi everyone!
This time I've got the problem .. and the solution, - I hope it will help someone someday. Software version:
Problem description: If there is a special symbol (like ³ or β) or a locale-specific symbols (Cyrillic for example) in the simulation (like Part name) or in path to the simulation or design manager project - design manager hangs up and Aborting it results in error like following: Quote:
Reason: When Star-CCM+ writes the .log-file ...\Design_Study\Design_1\Design_1.log encoded as 'cp1252', i.e. for example special character '«' (I had in Part's name Volume «Internal») is written down to file as 0xab (or \xab in Python notation). In Python scripts that .log-file is open()'ed assuming the file is in unicode (utf-8), thus it expects that '«' to be written down as 0xc2 0xab (or [CODE]\xc2\xab[/I] in Python notation .. anyway it should be c2ab if you open the .log-file in hex editor. But it's not. Solution: The best solution would be to make STAR-CCM+ process just to write it's log encoded in utf-8. STAR-CCM+ process is launched by Python script instance at line 603 of processmanagement.py as Code:
self._process = subprocess.Popen(command, stdout=self.outfile_w if self.outfile_w else None, stderr=subprocess.STDOUT, stdin=(subprocess.DEVNULL if self._use_shell else None), universal_newlines=True, startupinfo=None, cwd=self._cwd if self._cwd else None, shell=(self._use_shell if sys.platform == 'win32' else self._use_shell), creationflags=creationflags_value, start_new_session=(self._subprocess_in_new_session and sys.platform != 'win32'), env=child_env) Code:
self._process = subprocess.Popen(command, stdout=self.outfile_w if self.outfile_w else None, stderr=subprocess.STDOUT, stdin=(subprocess.DEVNULL if self._use_shell else None), universal_newlines=True, startupinfo=None, cwd=self._cwd if self._cwd else None, shell=(self._use_shell if sys.platform == 'win32' else self._use_shell), creationflags=creationflags_value, start_new_session=(self._subprocess_in_new_session and sys.platform != 'win32'), env=child_env, encoding='utf-8') So, the workaround is - in Python-files
find every occurrence of call to 'open()' (like Code:
with open(self.get_outpath(), 'at') Code:
self._outfile_w = open(self.get_outpath(), 'w') Quote:
Code:
with open(self.get_outpath(), 'at', encoding='cp1252') as f: Code:
self._outfile_w = open(self.get_outpath(), 'w', encoding='cp1252') That solves the issue with the DesignManager and it runs ok. At least - for me ... Yet Special characters like Cyrillic symbols (might affect special symbols in your language) in project path are written to .log-file as the same symbol '?' (0x3F): Quote:
Any help/suggestions from anyone who has experience with Python more than I do are welcome. |
||||
|
|