Skip to content

Commit c56d8cb

Browse files
[rqd] Fix non ASCII chars (#1335)
- Ensure consistent handling of non-ASCII characters in logs - Always encode lines to ASCII with an 'ignore' option to discard non-ASCII characters. - Removed unused file_descriptor block and ensured consistent encoding logic. This change prevents UnicodeEncodeError and ensures consistent log outputs.
1 parent c345dff commit c56d8cb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

‎rqd/rqd/rqcore.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,13 @@ def runLinux(self):
318318
else:
319319
tempCommand += [self._createCommandFile(runFrame.command)]
320320

321-
if rqd.rqconstants.RQD_PREPEND_TIMESTAMP:
322-
file_descriptor = subprocess.PIPE
323-
else:
324-
file_descriptor = self.rqlog
325321
# pylint: disable=subprocess-popen-preexec-fn
326322
frameInfo.forkedCommand = subprocess.Popen(tempCommand,
327323
env=self.frameEnv,
328324
cwd=self.rqCore.machine.getTempPath(),
329325
stdin=subprocess.PIPE,
330-
stdout=file_descriptor,
331-
stderr=file_descriptor,
326+
stdout=subprocess.PIPE,
327+
stderr=subprocess.PIPE,
332328
close_fds=True,
333329
preexec_fn=os.setsid)
334330
finally:
@@ -343,6 +339,16 @@ def runLinux(self):
343339

344340
if rqd.rqconstants.RQD_PREPEND_TIMESTAMP:
345341
pipe_to_file(frameInfo.forkedCommand.stdout, frameInfo.forkedCommand.stderr, self.rqlog)
342+
else:
343+
with open(self.rqlog, 'a') as f:
344+
# Convert to ASCII while discarding characters that can not be encoded
345+
for line in frameInfo.forkedCommand.stdout:
346+
line = line.encode('ascii', 'ignore')
347+
f.write(line.decode('ascii') + '\n')
348+
for line in frameInfo.forkedCommand.stderr:
349+
line = line.encode('ascii', 'ignore')
350+
f.write(line.decode('ascii') + '\n')
351+
346352
returncode = frameInfo.forkedCommand.wait()
347353

348354
# Find exitStatus and exitSignal
@@ -1222,6 +1228,8 @@ def print_and_flush_ln(fd, last_timestamp):
12221228

12231229
remainder = lines[-1]
12241230
for line in lines[0:-1]:
1231+
# Convert to ASCII while discarding characters that can not be encoded
1232+
line = line.encode('ascii', 'ignore')
12251233
print("[%s] %s" % (curr_line_timestamp, line), file=outfile)
12261234
outfile.flush()
12271235
os.fsync(outfile)

0 commit comments

Comments
 (0)