I have referred the other questions regarding the same error. But I would not want to specify an encoding, and just want to skip to the next line. Is it possible to ignore errors
in readline()
and read next?
I am using find
utility to get files older than 30 days. and it returns the files with full path. But when a different user used the code for another path, he got the encoding error. So if there is an error in stdout.readline()
then I want to skip the line and move to next. Does stdout.readline()
allow something like skip on errors?
Also in this given scenario of find
result, Can I use utf-8
encoding and be sure the paths will be read without errors?
find_cmd = ['find', '/a/b', '-mtime', f'+30', '-readable', '-type', 'f', '-print']
j = ' '.join(find_cmd)
proc = subprocess.Popen(j, universal_newlines=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
file = proc.stdout.readline().replace('\n', '') #Error here 'utf-8' codec can't decode byte 0xe4 in position 1478: invalid continuation byte
if not file: break
movefile(file)