def program_exists(program):
 proc = Popen(['which', program], stdout=PIPE, stderr=PIPE)
 txt = proc.communicate()
 if ((txt[0].strip() == '') and (txt[1].strip() == '')):
  return False
 if ((txt[0].strip() != '') and (txt[1].strip() == '')):
  return True
 return (not ((txt[1].strip() == '') or (txt[1].find(('no %s in' % program)) != (-1))))

def program_exists ( program ) : proc = Popen ( [ 'which' , program ] , stdout = PIPE , stderr = PIPE ) txt = proc . communicate ( ) if ( ( txt [ 0 ] . strip ( ) == '' ) and ( txt [ 1 ] . strip ( ) == '' ) ) : return False if ( ( txt [ 0 ] . strip ( ) != '' ) and ( txt [ 1 ] . strip ( ) == '' ) ) : return True return ( not ( ( txt [ 1 ] . strip ( ) == '' ) or ( txt [ 1 ] . find ( ( 'no %s in' % program ) ) != ( - 1 ) ) ) )
uses which to check if a program is installed .