Hello,
I am trying to get the terminal output from python to a text file with one row at a time.
It’s working, but there are some characters in the output to the file which are not in the terminal:
a question mark in a square
Does anyone know what’s wrong here, tried to replace them with a space, but that’s not working either?
Screenshot is attached
import subprocess
import sys
log_file = open('log_file.txt', 'a', encoding="UTF-8")
p = subprocess.Popen('winget install Google.chrome --accept-source-agreements' ,stdout = subprocess.PIPE, stderr= subprocess.PIPE)
# Poll process for new output until finished
while True:
nextline = p.stdout.readline()
#print(nextline)
if nextline == b'' and p.poll() != None:
break
sys.stdout.write(nextline.decode(sys.stdout.encoding))
log_file.write(nextline.decode(sys.stdout.encoding, errors="ignore"))
log_file.write(nextline.decode(sys.stdout.encoding))
output = p.communicate()[0]
exitCode = p.returncode