Subprocess check_output returned non-zero exit status 1 Subprocess check_output returned non-zero exit status 1 python-3.x python-3.x

Subprocess check_output returned non-zero exit status 1


The command yum that you launch was executed properly. It returns a non zero status which means that an error occured during the processing of the command. You probably want to add some argument to your yum command to fix that.

Your code could show this error this way:

import subprocesstry:    subprocess.check_output("dir /f",shell=True,stderr=subprocess.STDOUT)except subprocess.CalledProcessError as e:    raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))


The word check_ in the name means that if the command (the shell in this case that returns the exit status of the last command (yum in this case)) returns non-zero status then it raises CalledProcessError exception. It is by design. If the command that you want to run may return non-zero status on success then either catch this exception or don't use check_ methods. You could use subprocess.call in your case because you are ignoring the captured output, e.g.:

import subprocessrc = subprocess.call(['grep', 'pattern', 'file'],                     stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)if rc == 0: # found   ...elif rc == 1: # not found   ...elif rc > 1: # error   ...

You don't need shell=True to run the commands from your question.