Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f1512a29
Commit
f1512a29
authored
Jun 21, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #12383: Fix subprocess module with env={}: don't copy the environment
variables, start with an empty environment.
parent
b7149cad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
8 deletions
+20
-8
Lib/subprocess.py
Lib/subprocess.py
+1
-1
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+16
-7
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/subprocess.py
View file @
f1512a29
...
...
@@ -1169,7 +1169,7 @@ class Popen(object):
# potential deadlocks, thus we do all this here.
# and pass it to fork_exec()
if
env
:
if
env
is
not
None
:
env_list
=
[
os
.
fsencode
(
k
)
+
b'='
+
os
.
fsencode
(
v
)
for
k
,
v
in
env
.
items
()]
else
:
...
...
Lib/test/test_subprocess.py
View file @
f1512a29
...
...
@@ -331,13 +331,22 @@ class ProcessTestCase(BaseTestCase):
def
test_env
(
self
):
newenv
=
os
.
environ
.
copy
()
newenv
[
"FRUIT"
]
=
"orange"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import sys,os;'
'sys.stdout.write(os.getenv("FRUIT"))'
],
stdout
=
subprocess
.
PIPE
,
env
=
newenv
)
self
.
addCleanup
(
p
.
stdout
.
close
)
self
.
assertEqual
(
p
.
stdout
.
read
(),
b"orange"
)
with
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import sys,os;'
'sys.stdout.write(os.getenv("FRUIT"))'
],
stdout
=
subprocess
.
PIPE
,
env
=
newenv
)
as
p
:
stdout
,
stderr
=
p
.
communicate
()
self
.
assertEqual
(
stdout
,
b"orange"
)
def
test_empty_env
(
self
):
with
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import os; '
'print(len(os.environ))'
],
stdout
=
subprocess
.
PIPE
,
env
=
{})
as
p
:
stdout
,
stderr
=
p
.
communicate
()
self
.
assertEqual
(
stdout
.
strip
(),
b"0"
)
def
test_communicate_stdin
(
self
):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
...
...
Misc/NEWS
View file @
f1512a29
...
...
@@ -25,6 +25,9 @@ Core and Builtins
Library
-------
- Issue #12383: Fix subprocess module with env={}: don't copy the environment
variables, start with an empty environment.
- Issue #11584: email.header.decode_header no longer fails if the header
passed to it is a Header object, and Header/make_header no longer fail
if given binary unknown-8bit input.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment