diff --git a/pyanaconda/core/util.py b/pyanaconda/core/util.py index 80fd05f356e..238118e7eb6 100644 --- a/pyanaconda/core/util.py +++ b/pyanaconda/core/util.py @@ -286,6 +286,26 @@ def execWithCapture(command, argv, stdin=None, root='/', env_prune=None, env_add return _run_program(argv, stdin=stdin, root=root, log_output=log_output, env_prune=env_prune, env_add=env_add, filter_stderr=filter_stderr, do_preexec=do_preexec)[1] +def execProgram(command, argv, stdin=None, root='/', env_prune=None, env_add=None, + log_output=True, filter_stderr=False, do_preexec=True): + """ Run an external program and capture standard out and err as well as the return code. + + :param command: The command to run + :param argv: The argument list + :param stdin: The file object to read stdin from. + :param root: The directory to chroot to before running command. + :param env_prune: environment variable to remove before execution + :param env_add: environment variables added for the execution + :param log_output: Whether to log the output of command + :param filter_stderr: Whether stderr should be excluded from the returned output + :param do_preexec: whether to use the preexec function + :return: Tuple of the return code and the output of the command + """ + argv = [command] + argv + + return _run_program(argv, stdin=stdin, root=root, log_output=log_output, env_prune=env_prune, + env_add=env_add, filter_stderr=filter_stderr, do_preexec=do_preexec) + def execWithCaptureAsLiveUser(command, argv, stdin=None, root='/', log_output=True, filter_stderr=False, do_preexec=True): diff --git a/pyanaconda/modules/payloads/payload/rpm_ostree/installation.py b/pyanaconda/modules/payloads/payload/rpm_ostree/installation.py index 083f1187db9..c5c93e66e62 100644 --- a/pyanaconda/modules/payloads/payload/rpm_ostree/installation.py +++ b/pyanaconda/modules/payloads/payload/rpm_ostree/installation.py @@ -26,7 +26,7 @@ from pyanaconda.core.glib import GError, Variant, create_new_context, format_size_full from pyanaconda.core.i18n import _ from pyanaconda.core.path import make_directories, set_system_root -from pyanaconda.core.util import execWithRedirect +from pyanaconda.core.util import execWithRedirect, execProgram from pyanaconda.modules.common.constants.objects import BOOTLOADER, DEVICE_TREE from pyanaconda.modules.common.constants.services import LOCALIZATION, STORAGE from pyanaconda.modules.common.errors.installation import ( @@ -46,15 +46,16 @@ def safe_exec_with_redirect(cmd, argv, successful_return_codes=(0,), **kwargs): - """Like util.execWithRedirect, but treat errors as fatal. + """Like util.execProgram, but treat errors as fatal. :raise: PayloadInstallationError if the call fails for any reason """ - rc = execWithRedirect(cmd, argv, **kwargs) + rc, output = execProgram(cmd, argv, **kwargs) if rc not in successful_return_codes: raise PayloadInstallationError( - "The command '{}' exited with the code {}.".format(" ".join([cmd] + argv), rc) + "The command '{}' exited with the code {}:\n{}".format(" ".join([cmd] + argv), rc, + output) )