Skip to content

Commit

Permalink
Changed default encoding for pspawned processes on win32 to now be oe…
Browse files Browse the repository at this point in the history
…m. Updated CHANGES/RELEASE
  • Loading branch information
bdbaddog committed Sep 2, 2024
1 parent 320337c commit b0342f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER

From Anthony Siegrist;
- On win32 platform, handle piped process output more robustly. Output encoding
fallback to UTF8 if it is defined at None by the output stream object.
now uses 'oem' which should be the systems default encoding for the shell where
the process is being spawned.

From Mats Wichmann:
- env.Dump() now considers the "key" positional argument to be a varargs
Expand Down
5 changes: 3 additions & 2 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ FIXES
of the output encoding of piped processes. Instead of using the default
encoding, it relied on the encoding attribute of the output stream.
If the encoding attribute of the output stream was set to None,
it was triggering an invalid argument exeption. This was the case with
it was triggering an invalid argument exception. This was the case with
streams of type io.StringIO for example.
From now, if the encoding is set to None, UTF8 is used.
This has been changed to always use the `oem` encoding which should be the
encoding in the shell where the command was spawned.

IMPROVEMENTS
------------
Expand Down
12 changes: 2 additions & 10 deletions SCons/Platform/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,6 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
if not stderrRedirected:
args.append("2>" + tmpFileStderrName)

# Sanitize encoding. None is not a valid encoding.
# Since we're handling a redirected shell command use
# the shells default encoding.
if stdout.encoding is None:
stdout.encoding = 'oem'
if stderr.encoding is None:
stderr.encoding = 'oem'

# actually do the spawn
try:
args = [sh, '/C', escape(' '.join(args))]
Expand All @@ -175,7 +167,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
try:
with open(tmpFileStdoutName, "rb") as tmpFileStdout:
output = tmpFileStdout.read()
stdout.write(output.decode(stdout.encoding, "replace").replace("\r\n", "\n"))
stdout.write(output.decode('oem', "replace").replace("\r\n", "\n"))
os.remove(tmpFileStdoutName)
except OSError:
pass
Expand All @@ -184,7 +176,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
try:
with open(tmpFileStderrName, "rb") as tmpFileStderr:
errors = tmpFileStderr.read()
stderr.write(errors.decode(stderr.encoding, "replace").replace("\r\n", "\n"))
stderr.write(errors.decode('oem', "replace").replace("\r\n", "\n"))
os.remove(tmpFileStderrName)
except OSError:
pass
Expand Down

0 comments on commit b0342f5

Please sign in to comment.