Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
26576801
Kaydet (Commit)
26576801
authored
Ara 05, 2008
tarafından
Gregory P. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
rename the new check_call_output to check_output. its less ugly.
üst
17432013
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
26 deletions
+26
-26
subprocess.rst
Doc/library/subprocess.rst
+3
-3
subprocess.py
Lib/subprocess.py
+11
-11
test_subprocess.py
Lib/test/test_subprocess.py
+11
-11
NEWS
Misc/NEWS
+1
-1
No files found.
Doc/library/subprocess.rst
Dosyayı görüntüle @
26576801
...
...
@@ -149,7 +149,7 @@ This module also defines two shortcut functions:
.. versionadded:: 2.5
.. function:: check_
call_
output(*popenargs, **kwargs)
.. function:: check_output(*popenargs, **kwargs)
Run command with arguments and return its output as a byte string.
...
...
@@ -159,13 +159,13 @@ This module also defines two shortcut functions:
The arguments are the same as for the Popen constructor. Example:
>>> subprocess.check_
call_
output(["ls", "-l", "/dev/null"])
>>> subprocess.check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
The stdout argument is not allowed as it is used internally.
To capture standard error in the result, use stderr=subprocess.STDOUT.
>>> subprocess.check_
call_
output(
>>> subprocess.check_output(
["/bin/sh", "-c", "ls non_existant_file ; exit 0"],
stderr=subprocess.STDOUT)
'ls: non_existant_file: No such file or directory\n'
...
...
Lib/subprocess.py
Dosyayı görüntüle @
26576801
...
...
@@ -127,7 +127,7 @@ check_call(*popenargs, **kwargs):
check_call(["ls", "-l"])
check_
call_
output(*popenargs, **kwargs):
check_output(*popenargs, **kwargs):
Run command with arguments and return its output as a byte string.
If the exit code was non-zero it raises a CalledProcessError. The
...
...
@@ -136,7 +136,7 @@ check_call_output(*popenargs, **kwargs):
The arguments are the same as for the Popen constructor. Example:
output = subprocess.check_
call_
output(["ls", "-l", "/dev/null"])
output = subprocess.check_output(["ls", "-l", "/dev/null"])
Exceptions
----------
...
...
@@ -152,7 +152,7 @@ should prepare for OSErrors.
A ValueError will be raised if Popen is called with invalid arguments.
check_call() and check_
call_
output() will raise CalledProcessError, if the
check_call() and check_output() will raise CalledProcessError, if the
called process returns a non-zero return code.
...
...
@@ -373,9 +373,9 @@ import signal
# Exception classes used by this module.
class
CalledProcessError
(
Exception
):
"""This exception is raised when a process run by check_call() or
check_
call_
output() returns a non-zero exit status.
check_output() returns a non-zero exit status.
The exit status will be stored in the returncode attribute;
check_
call_
output() will also store the output in the output attribute.
check_output() will also store the output in the output attribute.
"""
def
__init__
(
self
,
returncode
,
cmd
,
output
=
None
):
self
.
returncode
=
returncode
...
...
@@ -418,7 +418,7 @@ else:
import
pickle
__all__
=
[
"Popen"
,
"PIPE"
,
"STDOUT"
,
"call"
,
"check_call"
,
"check_
call_
output"
,
"CalledProcessError"
]
"check_output"
,
"CalledProcessError"
]
try
:
MAXFD
=
os
.
sysconf
(
"SC_OPEN_MAX"
)
...
...
@@ -478,7 +478,7 @@ def check_call(*popenargs, **kwargs):
return
0
def
check_
call_
output
(
*
popenargs
,
**
kwargs
):
def
check_output
(
*
popenargs
,
**
kwargs
):
"""Run command with arguments and return its output as a byte string.
If the exit code was non-zero it raises a CalledProcessError. The
...
...
@@ -487,15 +487,15 @@ def check_call_output(*popenargs, **kwargs):
The arguments are the same as for the Popen constructor. Example:
>>> check_
call_
output(["ls", "-l", "/dev/null"])
>>> check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null
\n
'
The stdout argument is not allowed as it is used internally.
To capture standard error in the result, use stderr=subprocess.STDOUT.
>>> check_
call_
output(["/bin/sh", "-c",
"ls -l non_existant_file ; exit 0"],
stderr=subprocess.STDOUT)
>>> check_output(["/bin/sh", "-c",
"ls -l non_existant_file ; exit 0"],
stderr=subprocess.STDOUT)
'ls: non_existant_file: No such file or directory
\n
'
"""
if
'stdout'
in
kwargs
:
...
...
Lib/test/test_subprocess.py
Dosyayı görüntüle @
26576801
...
...
@@ -72,33 +72,33 @@ class ProcessTestCase(unittest.TestCase):
else
:
self
.
fail
(
"Expected CalledProcessError"
)
def
test_check_
call_
output
(
self
):
# check_
call_
output() function with zero return code
output
=
subprocess
.
check_
call_
output
(
def
test_check_output
(
self
):
# check_output() function with zero return code
output
=
subprocess
.
check_output
(
[
sys
.
executable
,
"-c"
,
"print 'BDFL'"
])
self
.
assertTrue
(
'BDFL'
in
output
)
def
test_check_
call_
output_nonzero
(
self
):
def
test_check_output_nonzero
(
self
):
# check_call() function with non-zero return code
try
:
subprocess
.
check_
call_
output
(
subprocess
.
check_output
(
[
sys
.
executable
,
"-c"
,
"import sys; sys.exit(5)"
])
except
subprocess
.
CalledProcessError
,
e
:
self
.
assertEqual
(
e
.
returncode
,
5
)
else
:
self
.
fail
(
"Expected CalledProcessError"
)
def
test_check_
call_
output_stderr
(
self
):
# check_
call_
output() function stderr redirected to stdout
output
=
subprocess
.
check_
call_
output
(
def
test_check_output_stderr
(
self
):
# check_output() function stderr redirected to stdout
output
=
subprocess
.
check_output
(
[
sys
.
executable
,
"-c"
,
"import sys; sys.stderr.write('BDFL')"
],
stderr
=
subprocess
.
STDOUT
)
self
.
assertTrue
(
'BDFL'
in
output
)
def
test_check_
call_
output_stdout_arg
(
self
):
# check_
call_
output() function stderr redirected to stdout
def
test_check_output_stdout_arg
(
self
):
# check_output() function stderr redirected to stdout
try
:
output
=
subprocess
.
check_
call_
output
(
output
=
subprocess
.
check_output
(
[
sys
.
executable
,
"-c"
,
"print 'will not be run'"
],
stdout
=
sys
.
stdout
)
except
ValueError
,
e
:
...
...
Misc/NEWS
Dosyayı görüntüle @
26576801
...
...
@@ -60,7 +60,7 @@ Core and Builtins
Library
-------
- Added the subprocess.check_
call_
output() convenience function to get output
- Added the subprocess.check_output() convenience function to get output
from a subprocess on success or raise an exception on error.
- Issue #1055234: cgi.parse_header(): Fixed parsing of header parameters to
...
...
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