Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

This is not a serious problem, just discuss it with curiosity. (For script)

(1/1)

Chun Jiu:
Hi guys,

I tried to use a script function to call the Python 3 program, and then get its feedback output.

But cannot get the correct non-ascii result.

Windows 10
local a=IO.ExecuteAndGetOutput(_T("python E:\\MyTest\\prt.py")); print(a.len());for (local i=0; i<a.len(); i++) {print (a.GetChar(i)); };; print(a);

Ubuntu 18.04.4
local a=IO.ExecuteAndGetOutput(_T("python3 /home/sam/prt.py")); print(a.len());for (local i=0; i<a.len(); i++) {print (a.GetChar(i)) };; print(a);


--- Code: ---#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

type = sys.stdout.encoding
print(type)
 
print("git 信息 ...  \n")

#print("git  信息...".encode('utf-8').decode(type))
print("git  信息...".decode('ascii'))

--- End code ---

I found that in ubuntu, non-ascii characters were deleted directly, and the ascii characters that were next to them were also lost.

In windows, non-ascii characters (utf-8) become garbled characters and cannot be recognized correctly after encoding conversion.


--- Code: ---> local a=IO.ExecuteAndGetOutput(_T("python E:\\MyTest\\prt.py")); print(a.len());for (local i=0; i<a.len(); i++) {print (a.GetChar(i)); };; print(a);
20
103
98
107
10
103
105
116
32
-61
-112
-61
-123
-61
-113
-62
-94
32
46
46
46
gbk
git ÐÅÏ¢ ... 

--- End code ---

So, what caused this?

Of course, this has no effect on my work, because I can use the Python 3 program to parse the string, and then return a standard ascii result to the script.

Just curious to ask if this problem can be solved in script.

BlueHazzard:
The garbage output from

--- Code: ---print(a)
--- End code ---
is probably  the font of the script output console window...

Chun Jiu:

--- Quote from: BlueHazzard on July 10, 2020, 07:27:31 am ---The garbage output from

--- Code: ---print(a)
--- End code ---
is probably  the font of the script output console window...

--- End quote ---

Maybe this is the case, when I am interested and free, maybe I will trace the underlying code.

  ;)

Navigation

[0] Message Index

Go to full version