G
G
guitarjedi2018-05-28 14:34:20
Python
guitarjedi, 2018-05-28 14:34:20

How to set subprocess.Popen encoding?

Good afternoon! From under Windows, I send csv'xy to a third-party application using:

proc = subprocess.Popen(['powershell', 'cat ' + confCSV + ' | clickhouse-cli --host=' + confClick + ' --query="INSERT INTO ' + confDb + ' FORMAT CSV"'])
proc.wait()

Everything is fine, but the data arrives not in UTF-8, but in the form ???????????, it should be Cyrillic. After changing the encoding in powershell to chcp 65001 or chcp850, directly from powershell (If you run the command from the script in the powershell console), the data flies normally, through subprocess.Popen it also flows from the script, I don’t understand how, in the form of questions. Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2018-05-28
@chupasaurus

Add first command to PoSH

[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding;
or& "$env:windir\system32\chcp.com" 65001;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question