Author Topic: This is not a serious problem, just discuss it with curiosity. (For script)  (Read 4797 times)

Offline Chun Jiu

  • Multiple posting newcomer
  • *
  • Posts: 71
  • My Girlfriend
    • EasilyGCC
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'))

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 ÐÅÏ¢ ... 

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.
I love my girlfriend like c++!    :-)

http://pan.baidu.com/s/1feNwU
easilygcc is a gmail's email.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
The garbage output from
Code
print(a)
is probably  the font of the script output console window...

Offline Chun Jiu

  • Multiple posting newcomer
  • *
  • Posts: 71
  • My Girlfriend
    • EasilyGCC
The garbage output from
Code
print(a)
is probably  the font of the script output console window...

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

  ;)
I love my girlfriend like c++!    :-)

http://pan.baidu.com/s/1feNwU
easilygcc is a gmail's email.