Fix compilation using subprocesses (#2834)

This commit is contained in:
Oxan van Leeuwen 2021-12-01 17:37:24 +01:00 committed by GitHub
parent 24a5325db3
commit fbe1bca1b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -219,24 +219,23 @@ def run_external_process(*cmd, **kwargs):
capture_stdout = kwargs.get("capture_stdout", False)
if capture_stdout:
sub_stdout = io.BytesIO()
sub_stdout = subprocess.PIPE
else:
sub_stdout = RedirectText(sys.stdout, filter_lines=filter_lines)
sub_stderr = RedirectText(sys.stderr, filter_lines=filter_lines)
try:
return subprocess.call(cmd, stdout=sub_stdout, stderr=sub_stderr)
proc = subprocess.run(
cmd, stdout=sub_stdout, stderr=sub_stderr, encoding="utf-8", check=False
)
return proc.stdout if capture_stdout else proc.returncode
except KeyboardInterrupt: # pylint: disable=try-except-raise
raise
except Exception as err: # pylint: disable=broad-except
_LOGGER.error("Running command failed: %s", err)
_LOGGER.error("Please try running %s locally.", full_cmd)
return 1
finally:
if capture_stdout:
# pylint: disable=lost-exception
return sub_stdout.getvalue()
def is_dev_esphome_version():