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 10local 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.4local 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);
#!/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.
> 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.