def ps(cmd):
 if (not LINUX):
  cmd = cmd.replace(' --no-headers ', ' ')
 if SUNOS:
  cmd = cmd.replace('-o command', '-o comm')
  cmd = cmd.replace('-o start', '-o stime')
 p = subprocess.Popen(cmd, shell=1, stdout=subprocess.PIPE)
 output = p.communicate()[0].strip()
 if PY3:
  output = str(output, sys.stdout.encoding)
 if (not LINUX):
  output = output.split('\n')[1].strip()
 try:
  return int(output)
 except ValueError:
  return output

def ps ( cmd ) : if ( not LINUX ) : cmd = cmd . replace ( ' --no-headers ' , ' ' ) if SUNOS : cmd = cmd . replace ( '-o command' , '-o comm' ) cmd = cmd . replace ( '-o start' , '-o stime' ) p = subprocess . Popen ( cmd , shell = 1 , stdout = subprocess . PIPE ) output = p . communicate ( ) [ 0 ] . strip ( ) if PY3 : output = str ( output , sys . stdout . encoding ) if ( not LINUX ) : output = output . split ( '\n' ) [ 1 ] . strip ( ) try : return int ( output ) except ValueError : return output
expects a ps command with a -o argument and parse the result returning only the value of interest .