@@ -2030,24 +2030,28 @@ def _pformat_subprocess(command):
2030
2030
2031
2031
def _check_and_log_subprocess (command , logger , ** kwargs ):
2032
2032
"""
2033
- Run *command* using `subprocess.check_output`. If it succeeds, return the
2034
- output (stdout and stderr); if not, raise an exception whose text includes
2035
- the failed command and captured output. Both the command and the output
2036
- are logged at DEBUG level on *logger*.
2033
+ Run *command*, returning its stdout output if it succeeds.
2034
+
2035
+ If it fails (exits with nonzero return code), raise an exception whose text
2036
+ includes the failed command and captured stdout and stderr output.
2037
+
2038
+ Regardless of the return code, the command is logged at DEBUG level on
2039
+ *logger*. In case of success, the output is likewise logged.
2037
2040
"""
2038
2041
logger .debug ('%s' , _pformat_subprocess (command ))
2039
- try :
2040
- report = subprocess .check_output (
2041
- command , stderr = subprocess .STDOUT , ** kwargs )
2042
- except subprocess .CalledProcessError as exc :
2042
+ proc = subprocess .run (
2043
+ command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** kwargs )
2044
+ if proc .returncode :
2043
2045
raise RuntimeError (
2044
- 'The command\n '
2045
- ' {}\n '
2046
- 'failed and generated the following output:\n '
2047
- '{}'
2048
- .format (_pformat_subprocess (command ), exc .output .decode ('utf-8' )))
2049
- logger .debug (report )
2050
- return report
2046
+ f"The command\n "
2047
+ f" { _pformat_subprocess (command )} \n "
2048
+ f"failed and generated the following output:\n "
2049
+ f"{ proc .stdout .decode ('utf-8' )} \n "
2050
+ f"and the following error:\n "
2051
+ f"{ proc .stderr .decode ('utf-8' )} " )
2052
+ logger .debug ("stdout:\n %s" , proc .stdout )
2053
+ logger .debug ("stderr:\n %s" , proc .stderr )
2054
+ return proc .stdout
2051
2055
2052
2056
2053
2057
def _check_isinstance (types , ** kwargs ):
0 commit comments