def run(self, cmd, shell = False, kill_tree = True, timeout = -1, airodump = False):
    """
    Runs a command witha given time after wich is terminated
    returns stdout of proc.
    output is a list without passing strip() on the lines.
    """

    class Alarm(Exception):
      pass
    def alarm_handler(signum, frame):
      raise Alarm
    output = []
    if timeout != -1:
      signal(SIGALRM, alarm_handler) # Time's ticking...
      alarm(timeout)
    if airodump:
      proc = subprocess.Popen(cmd, shell = shell, stderr = subprocess.PIPE)
    else:
      proc = subprocess.Popen(cmd, shell = shell, stdout = subprocess.PIPE)
    try:
      if airodump:
	for line in iter(proc.stderr.readline, ''):
	  output.append(line)
	if timeout != -1:
	  alarm(0)
      else:
	for line in iter(proc.stdout.readline, ''):
	  output.append(line)
	if timeout != -1:
	  alarm(0)
    except Alarm:         # time's out! alarm is raised
      pids = [proc.pid]   # kill the process tree related with the main process.
      if airodump: system('pkill airodump')
      if kill_tree:
	pids.extend(self.get_process_children(proc.pid))
      for pid in pids:
	try:
	  kill(pid, SIGKILL)
	except __HOLE__:
	  pass
      return output
    return output
dataset/ETHPy150Open jgilhutton/pyxiewps_WPShack-Python/pyxiewps-EN.py/Engine.run