Page 1 of 1

Write to binary file writes "???"

Posted: Mon Jun 13, 2022 10:47 pm
by amolago
Hi,

We have worked around a problem with IA writing BOMs to text files, (and worked around a problem with writing to binary files not creating files like writing to text files does), with the following pseudo-code:

Code: Select all

Set Variable FILE_DATA to
Set Variable NEW_TEXT_VALUE to Lorum Ipsum
Read from Text File #READALL\config_file_in.txt into Variable FILE_DATA
Replace TEXT_TO_REPLACE with $NEW_TEXT_VALUE$ in variable FILE_DATA
Write into Text File config_file.txt from Value  (at end of file)
Write $FILE_DATA$ to binary file config_file.txt at offset 0


This works well and good for your usual ASCII text. But we have been surprised by a problem with non-ascii text. When, for example, Japanese text is written, all we get is "?????" in the file.

Why is this this case? I would have thought writing to a binary file would have simply written the data "as is" to the file because it's binary data!?

Demo project attached.

Re: Write to binary file writes "???"

Posted: Tue Jun 14, 2022 9:28 am
by FrancescoT
A binary file is a computer file that is not a text file. You cannot expect a different result if you try to write a TEXT CONTENT as BINARY CONTENT.

InstallAware full supports UNICODE. You simply need to write your "non-ascii text" as TEXT.

For example;

Code: Select all

Set Variable MY_VAR to こんにちは世界
Write into Text File c:\myfile.txt from Value $MY_VAR$ (at end of file)

Code: Select all

~InstallAware Clipboard Data~
~Write to Text File~
~{31DBF6F5-053C-4CBD-83E6-D5C9BA641599}~
~c:\myfile.txt~
~$MY_VAR$~
~FALSE~
~TRUE~
~Set Variable~
~{B90D5F2D-4BDD-49D5-AD15-3A077DAF6829}~
~MY_VAR$MYAH$MYAH$FALSE~
~こんにちは世界~

Japanese_helloworld_txt.png
Japanese_helloworld_txt.png (5.65 KiB) Viewed 3830 times


Hope this helps you.