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
4575069f
Commit
4575069f
authored
Mar 27, 2011
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
5faa4d94
60001c48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
65 deletions
+2
-65
Lib/subprocess.py
Lib/subprocess.py
+0
-65
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/subprocess.py
View file @
4575069f
...
...
@@ -1723,68 +1723,3 @@ class Popen(object):
"""Kill the process with SIGKILL
"""
self
.
send_signal
(
signal
.
SIGKILL
)
def
_demo_posix
():
#
# Example 1: Simple redirection: Get process list
#
plist
=
Popen
([
"ps"
],
stdout
=
PIPE
).
communicate
()[
0
]
print
(
"Process list:"
)
print
(
plist
)
#
# Example 2: Change uid before executing child
#
if
os
.
getuid
()
==
0
:
p
=
Popen
([
"id"
],
preexec_fn
=
lambda
:
os
.
setuid
(
100
))
p
.
wait
()
#
# Example 3: Connecting several subprocesses
#
print
(
"Looking for 'hda'..."
)
p1
=
Popen
([
"dmesg"
],
stdout
=
PIPE
)
p2
=
Popen
([
"grep"
,
"hda"
],
stdin
=
p1
.
stdout
,
stdout
=
PIPE
)
print
(
repr
(
p2
.
communicate
()[
0
]))
#
# Example 4: Catch execution error
#
print
()
print
(
"Trying a weird file..."
)
try
:
print
(
Popen
([
"/this/path/does/not/exist"
]).
communicate
())
except
OSError
as
e
:
if
e
.
errno
==
errno
.
ENOENT
:
print
(
"The file didn't exist. I thought so..."
)
print
(
"Child traceback:"
)
print
(
e
.
child_traceback
)
else
:
print
(
"Error"
,
e
.
errno
)
else
:
print
(
"Gosh. No error."
,
file
=
sys
.
stderr
)
def
_demo_windows
():
#
# Example 1: Connecting several subprocesses
#
print
(
"Looking for 'PROMPT' in set output..."
)
p1
=
Popen
(
"set"
,
stdout
=
PIPE
,
shell
=
True
)
p2
=
Popen
(
'find "PROMPT"'
,
stdin
=
p1
.
stdout
,
stdout
=
PIPE
)
print
(
repr
(
p2
.
communicate
()[
0
]))
#
# Example 2: Simple execution of program
#
print
(
"Executing calc..."
)
p
=
Popen
(
"calc"
)
p
.
wait
()
if
__name__
==
"__main__"
:
if
mswindows
:
_demo_windows
()
else
:
_demo_posix
()
Misc/NEWS
View file @
4575069f
...
...
@@ -87,6 +87,8 @@ Core and Builtins
Library
-------
-
Issue
#
11692
:
Remove
unnecessary
demo
functions
in
subprocess
module
.
-
Issue
#
9696
:
Fix
exception
incorrectly
raised
by
xdrlib
.
Packer
.
pack_int
when
trying
to
pack
a
negative
(
in
-
range
)
integer
.
...
...
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