Opened 17 years ago
Closed 17 years ago
#919 closed Bug (Fixed)
Binary() is ignored in ConsoleWrite()
| Reported by: | jchd | Owned by: | Valik |
|---|---|---|---|
| Milestone: | 3.3.1.0 | Component: | AutoIt |
| Version: | 3.3.0.0 | Severity: | Blocking |
| Keywords: | Cc: |
Description
The code below shows the problem.
Global $s = "Bug"
ConsoleWrite(Binary("Bug")) ; here Binary() is completely ignored!
ConsoleWrite(@LF)
ConsoleWrite(Binary($s)) ; again Binary() is completely ignored!
ConsoleWrite(@LF)
ConsoleWrite(Binary("Correct") & @LF) ; a concatenation is a workaround
ConsoleWrite(Binary("Correct") & "") ; any concatenation is a workaround
ConsoleWrite(@LF)
Attachments (0)
Change History (10)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
| Resolution: | → No Bug |
|---|---|
| Status: | new → closed |
I was correct, this is an intentional change. See #13. Closing as no bug.
comment:3 by , 17 years ago
| Resolution: | No Bug |
|---|---|
| Status: | closed → reopened |
Reopening so I remember to document how binary data works.
In addition StdinWrite(), ConsoleWrite() and ConsoleWriteError() need updated.
comment:4 by , 17 years ago
| Owner: | set to |
|---|---|
| Status: | reopened → assigned |
follow-up: 6 comment:5 by , 17 years ago
| Severity: | None → Blocking |
|---|
This needs addressed before the next beta is released. Setting the blocking flag to reflect that. Simple documentation change.
follow-up: 7 comment:6 by , 17 years ago
Replying to Valik:
Intentional change. Simple documentation change.
OK Valik I now understand this behavior better and the reason behind it.
In the meantime I've worked hard along with JPM to clarify the behavior of ConsoleWrite w.r.t. non-ASCII/ANSI strings.
It can be made to display Unicode (native AutoIt strings) fully. This is used with success in the proposed sqlite.au3 currently under review. If you want to see it at work just drop me a note and I'll send you this UDF (or ask JPM in case you still want to avoid talking to me). Perhaps would it be a good thing to have it work this way in the core so that string display is consistent.
comment:7 by , 17 years ago
Replying to jchd:
Replying to Valik:
Intentional change. Simple documentation change.
OK Valik I now understand this behavior better and the reason behind it.
In the meantime I've worked hard along with JPM to clarify the behavior of ConsoleWrite w.r.t. non-ASCII/ANSI strings.
Somehow I doubt that. I honestly do not care what either your or JP think about this. I can virtually guarantee you are missing something rather obvious and I have enough bullshit to deal with without concerning myself with this.
comment:8 by , 17 years ago
At least the internal function SQLite_ConsoleWriteUTF8() in SQLite.au3 demonstrate that something can be done. I don't know if it can be generalized.
comment:9 by , 17 years ago
Congratulations, you learned how to set output.code.page=65001 in SciTE. That's meaningless. I'm not at all surprised you can pass a UTF-8 string to SciTE and get it to display UTF-8. Now try something that matters like a real console application. Compile the following script as a console application:
Local Const $sSource = ChrW(0x107) ; LATIN SMALL LETTER C WITH ACUTE
ConsoleWrite($sSource & @CRLF)
__SQLite_ConsoleWriteUTF8($sSource & @CRLF)
MsgBox(4096, "", $sSource)
Func __SQLite_ConsoleWriteUTF8($sString)
Local $tStr8 = __SQLite_StringToUtf8Struct($sString)
ConsoleWrite(DllStructGetData($tStr8, 1))
EndFunc ;==>__SQLite_ConsoleWriteUTF8
Func __SQLite_StringToUtf8Struct($sString)
Local $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _
"ptr", 0, "int", 0, "ptr", 0, "ptr", 0)
If @error Then Return SetError(1, @error, "") ; Dllcall error
Local $tText = DllStructCreate("char[" & $aResult[0] & "]")
$aResult = DllCall("Kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _
"ptr", DllStructGetPtr($tText), "int", $aResult[0], "ptr", 0, "ptr", 0)
If @error Then Return SetError(2, @error, "") ; Dllcall error
Return($tText)
EndFunc ;==>__SQLite_StringToUtf8Struct
Run the script and check the output in the console window when the message box is showing. You'll see this:
c
─ç
Console windows are ANSI-only. AutoIt's ConsoleWrite() is compatible with real console windows. Thus, AutoIt's ConsoleWrite() is ANSI-only. If you wish to write UTF-8 to ConsoleWrite(), be my guest. But don't expect the stream reader to display anything meaningful just because ScITE can (and even then, I still had to manually configure SciTE since it displayed garbage before I changed output.code.page).
comment:10 by , 17 years ago
| Milestone: | → 3.3.1.0 |
|---|---|
| Resolution: | → Fixed |
| Status: | assigned → closed |
Fixed in version: 3.3.1.0

I do not think this is a bug. I am trying to remember why this is happening but it is certainly an intentional design.