Write to binary file writes "???"

Got a problem you cannot solve? Try here.
amolago
Posts: 12
Joined: Wed Oct 29, 2014 9:15 pm

Write to binary file writes "???"

Postby amolago » Mon Jun 13, 2022 10:47 pm

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.
Attachments
binary_problem.zip
Demo project
(1.68 KiB) Downloaded 117 times

FrancescoT
Site Admin
Posts: 5360
Joined: Sun Aug 22, 2010 4:28 am

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

Postby FrancescoT » Tue Jun 14, 2022 9:28 am

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 1701 times


Hope this helps you.
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 41 guests