title: How do I process results from subprocess check_output
body: <p>I am trying to do to check AWS ECR if there is an existing image in ECR. If it has, the script will not proceed to push the image into ecr. If it doesnt, the script will push it to ECR.</p>
  <p>python script:</p>
  <pre><code>command = &quot;aws ecr describe-images --repository-name &quot; + source['reponame'] + &quot; --image-ids imageTag=&quot; + tag + &quot; --query 'imageDetails[0].imageTags[*]'&quot;
      
  result = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
  </code></pre>
  <p>I'm having this issue where it is returning me this error.</p>
  <pre><code>subprocess.CalledProcessError: Command 'aws ecr describe-images --repository-name dummyrepo --image-ids imageTag=1.1.1 --query 'imageDetails[0].imageTags[*]'' returned non-zero exit status 255.
  </code></pre>
  <p>I know that when i run the same command on cli, I will get this when it has an image.</p>
  <pre><code>[
      &quot;1.0.1&quot;
  ]
  </code></pre>
  <p>And this when the image does not exist.</p>
  <pre><code>An error occurred (ImageNotFoundException) when calling the DescribeImages operation: The image with imageId {imageDigest:'null', imageTag:'1.1.1'} does not exist within the repository with name 'dummyrepo' in the registry with id 'xxxxxxx'
  </code></pre>
  <p>How do I overcome this error ?</p>