title: How to use several subprocess.check_output and avoid non-zero exit status 67
body: <p>I'm at the beginning of learning python, so it may be something obvious. I'm trying to create a script that will change the desktop pictures in OS X 10.9 according to group membership.
  If I only check for one thing, the script works. It's when I try to expend on it that I fail.
  I've tried putting all the declarations before the if else, also tried it with if elif else.</p>
  
  <p>How does one get python to use several subprocess.check_output in a row?</p>
  
  <p>The script dies with this traceback:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):<br>
      File "/Library/SetDesktopImages/SetDesktopImages.py", line 36, in module<br>
        CheckStudentUser = subprocess.check_output(['dseditgroup', '-o' , 'checkmember', '-m', username, 'students'])<br>
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 575, in check_output<br>
        raise CalledProcessError(retcode, cmd, output=output)<br>
    subprocess.CalledProcessError: Command '['dseditgroup', '-o', 'checkmember', '-m', 'root', 'students']' returned non-zero exit status 67</p>
  </blockquote>
  
  <p>If I run the command itself, it is fine:</p>
  
  <p>$ dseditgroup -o checkmember -m root students<br>
  no root is NOT a member of students</p>
  
  <p>Here is my script so far:</p>
  
  <pre><code>#!/usr/bin/python
  # This script checks the user's membership to groups in order to set the Desktop Picture.
  
  from AppKit import NSWorkspace, NSScreen
  from Foundation import NSURL
  import getpass
  import subprocess
  
  network_user_path = "/Library/Desktop Pictures/Abstract.jpg"
  ladmin_path = "/Library/Desktop Pictures/Desert.jpg"
  luser_path = "/Library/Desktop Pictures/Flamingos.jpg"
  
  # generate a fileURL
  nu_file_url = NSURL.fileURLWithPath_(network_user_path)
  la_file_url = NSURL.fileURLWithPath_(ladmin_path)
  lu_file_url = NSURL.fileURLWithPath_(luser_path)
  
  username=getpass.getuser()
  options = {}
  ws = NSWorkspace.sharedWorkspace()
  
  CheckAdminUser = subprocess.check_output(['dseditgroup', '-o' , 'checkmember', '-m', username, 'admin'])
  IsAdmin = subprocess.check_output(['echo', CheckAdminUser, '|', 'cut', '-d', '-f1', '|', 'awk', '{print $1}'])
  
  if IsAdmin == 'yes':
      for screen in NSScreen.screens():
          (result, error) = ws.setDesktopImageURL_forScreen_options_error_(
                                                                       la_file_url, screen, options, None)
  else:
  
      CheckStudentUser = subprocess.check_output(['dseditgroup', '-o' , 'checkmember', '-m', username, 'students'])
      IsStudent = subprocess.check_output(['echo', CheckStudentUser, '|', 'cut', '-d', '-f1', '|', 'awk', '{print $1}'])
  
  if IsStudent == 'yes':
          for screen in NSScreen.screens():
              (result, error) = ws.setDesktopImageURL_forScreen_options_error_(
                                                                       nu_file_url, screen, options, None)
  else:
      CheckLocalUser = subprocess.check_output(['dseditgroup', '-o' , 'checkmember', '-m', username, 'localaccounts'])
      IsLocal = subprocess.check_output(['echo', CheckLocalUser, '|', 'cut', '-d', '-f1', '|', 'awk', '{print $1}'])
  
  if IsLocal == 'yes':
          for screen in NSScreen.screens():
              (result, error) = ws.setDesktopImageURL_forScreen_options_error_(
                                                                       lu_file_url, screen, options, None)
  # not sure about this ending
  else:
      exit0
  </code></pre>