code: def process_stdin(line):
      '''handle commands from user'''
      if line is None:
          sys.exit(0)
  
      line = line.strip()
      if not line:
          return
  
      args = shlex.split(line)
      cmd = args[0]
      if cmd == 'help':
          k = command_map.keys()
          k.sort()
          for cmd in k:
              (fn, help) = command_map[cmd]
              print("%-15s : %s" % (cmd, help))
          return
      if cmd == 'exit':
          mestate.exit = True
          return
  
      if not cmd in command_map:
          print("Unknown command '%s'" % line)
          return
      (fn, help) = command_map[cmd]
      try:
          fn(args[1:])
      except Exception as e:
          print("ERROR in command %s: %s" % (args[1:], str(e))f process_stdin(line):
      '''handle commands from user'''
      if line is None:
          sys.exit(0)
  
      line = line.strip()
      if not line:
          return
  
      args = shlex.split(line)
      cmd = args[0]
      if cmd == 'help':
          k = command_map.keys()
          k.sort()
          for cmd in k:
              (fn, help) = command_map[cmd]
              print("%-15s : %s" % (cmd, help))
          return
      if cmd == 'exit':
          mestate.exit = True
          return
  
      if not cmd in command_map:
          print("Unknown command '%s'" % line)
          return
      (fn, help) = command_map[cmd]
      try:
          fn(args[1:])
      except Exception as e:
          print("ERROR in command %s: %s" % (args[1:], str(e)))
docs: handle commands from user