News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

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

Started by Chun Jiu, July 09, 2020, 02:37:00 PM

Previous topic - Next topic

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);


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

[url="http://pan.baidu.com/s/1feNwU"]http://pan.baidu.com/s/1feNwU[/url]
easilygcc is a gmail's email.

BlueHazzard

The garbage output from
print(a)
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
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++!    :-)

[url="http://pan.baidu.com/s/1feNwU"]http://pan.baidu.com/s/1feNwU[/url]
easilygcc is a gmail's email.