{
    "mode": "pydoc",
    "parameter": "cmd",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/cmd/json",
    "generated": "2026-06-02T14:16:01Z",
    "sections": {
        "NAME": {
            "content": "cmd - A generic class to build line-oriented command interpreters.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/cmd.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Interpreters constructed with this class obey the following conventions:\n\n1. End of file on input is processed as the command 'EOF'.\n2. A command is parsed out of each line by collecting the prefix composed\nof characters in the identchars member.\n3. A command `foo' is dispatched to a method 'dofoo()'; the do method\nis passed a single argument consisting of the remainder of the line.\n4. Typing an empty line repeats the last command.  (Actually, it calls the\nmethod `emptyline', which may be overridden in a subclass.)\n5. There is a predefined `help' method.  Given an argument `topic', it\ncalls the command `helptopic'.  With no arguments, it lists all topics\nwith defined help functions, broken into up to three topics; documented\ncommands, miscellaneous help topics, and undocumented commands.\n6. The command '?' is a synonym for `help'.  The command '!' is a synonym\nfor `shell', if a doshell method exists.\n7. If completion is enabled, completing commands will be done automatically,\nand completing of commands args is done by calling completefoo() with\narguments text, line, begidx, endidx.  text is string we are matching\nagainst, all returned matches must begin with it.  line is the current\ninput line (lstripped), begidx and endidx are the beginning and end\nindexes of the text being matched, which could be used to provide\ndifferent completion depending upon which position the argument is in.\n\nThe `default' method may be overridden to intercept commands for which there\nis no do method.\n\nThe `completedefault' method may be overridden to intercept completions for\ncommands that have no complete method.\n\nThe data member `self.ruler' sets the character used to draw separator lines\nin the help messages.  If empty, no ruler line is drawn.  It defaults to \"=\".\n\nIf the value of `self.intro' is nonempty when the cmdloop method is called,\nit is printed out on interpreter startup.  This value may be overridden\nvia an optional argument to the cmdloop() method.\n\nThe data members `self.docheader', `self.mischeader', and\n`self.undocheader' set the headers used for the help function's\nlistings of documented functions, miscellaneous topics, and undocumented\nfunctions respectively.\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.object\nCmd\n",
            "subsections": [
                {
                    "name": "class Cmd",
                    "content": "|  Cmd(completekey='tab', stdin=None, stdout=None)\n|\n|  A simple framework for writing line-oriented command interpreters.\n|\n|  These are often useful for test harnesses, administrative tools, and\n|  prototypes that will later be wrapped in a more sophisticated interface.\n|\n|  A Cmd instance or subclass instance is a line-oriented interpreter\n|  framework.  There is no good reason to instantiate Cmd itself; rather,\n|  it's useful as a superclass of an interpreter class you define yourself\n|  in order to inherit Cmd's methods and encapsulate action methods.\n|\n|  Methods defined here:\n|\n|  init(self, completekey='tab', stdin=None, stdout=None)\n|      Instantiate a line-oriented interpreter framework.\n|\n|      The optional argument 'completekey' is the readline name of a\n|      completion key; it defaults to the Tab key. If completekey is\n|      not None and the readline module is available, command completion\n|      is done automatically. The optional arguments stdin and stdout\n|      specify alternate input and output file objects; if not specified,\n|      sys.stdin and sys.stdout are used.\n|\n|  cmdloop(self, intro=None)\n|      Repeatedly issue a prompt, accept input, parse an initial prefix\n|      off the received input, and dispatch to action methods, passing them\n|      the remainder of the line as argument.\n|\n|  columnize(self, list, displaywidth=80)\n|      Display a list of strings as a compact set of columns.\n|\n|      Each column is only as wide as necessary.\n|      Columns are separated by two spaces (one was not legible enough).\n|\n|  complete(self, text, state)\n|      Return the next possible completion for 'text'.\n|\n|      If a command has not been entered, then complete against command list.\n|      Otherwise try to call complete<command> to get list of completions.\n|\n|  completehelp(self, *args)\n|\n|  completedefault(self, *ignored)\n|      Method called to complete an input line when no command-specific\n|      complete*() method is available.\n|\n|      By default, it returns an empty list.\n|\n|  completenames(self, text, *ignored)\n|\n|  default(self, line)\n|      Called on an input line when the command prefix is not recognized.\n|\n|      If this method is not overridden, it prints an error message and\n|      returns.\n|\n|  dohelp(self, arg)\n|      List available commands with \"help\" or detailed help with \"help cmd\".\n|\n|  emptyline(self)\n|      Called when an empty line is entered in response to the prompt.\n|\n|      If this method is not overridden, it repeats the last nonempty\n|      command entered.\n|\n|  getnames(self)\n|\n|  onecmd(self, line)\n|      Interpret the argument as though it had been typed in response\n|      to the prompt.\n|\n|      This may be overridden, but should not normally need to be;\n|      see the precmd() and postcmd() methods for useful execution hooks.\n|      The return value is a flag indicating whether interpretation of\n|      commands by the interpreter should stop.\n|\n|  parseline(self, line)\n|      Parse the line into a command name and a string containing\n|      the arguments.  Returns a tuple containing (command, args, line).\n|      'command' and 'args' may be None if the line couldn't be parsed.\n|\n|  postcmd(self, stop, line)\n|      Hook method executed just after a command dispatch is finished.\n|\n|  postloop(self)\n|      Hook method executed once when the cmdloop() method is about to\n|      return.\n|\n|  precmd(self, line)\n|      Hook method executed just before the command line is\n|      interpreted, but after the input prompt is generated and issued.\n|\n|  preloop(self)\n|      Hook method executed once when the cmdloop() method is called.\n|\n|  printtopics(self, header, cmds, cmdlen, maxcol)\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Data and other attributes defined here:\n|\n|  docheader = 'Documented commands (type help <topic>):'\n|\n|  docleader = ''\n|\n|  identchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123...\n|\n|  intro = None\n|\n|  lastcmd = ''\n|\n|  mischeader = 'Miscellaneous help topics:'\n|\n|  nohelp = '* No help on %s'\n|\n|  prompt = '(Cmd) '\n|\n|  ruler = '='\n|\n|  undocheader = 'Undocumented commands:'\n|\n|  userawinput = 1\n"
                }
            ]
        },
        "DATA": {
            "content": "all = ['Cmd']\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.10/cmd.py\n\n",
            "subsections": []
        }
    },
    "summary": "cmd - A generic class to build line-oriented command interpreters.",
    "flags": [],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "cheatsh",
        "description": "",
        "examples": [
            {
                "description": "Start an interactive shell session:",
                "command": "cmd"
            },
            {
                "description": "Execute specific [c]ommands:",
                "command": "cmd {{path}} echo Hello world"
            },
            {
                "description": "Execute a specific script:",
                "command": "cmd path\\to\\script.bat"
            },
            {
                "description": "Execute specific commands and then enter an interactive shell:",
                "command": "cmd {{path}} echo Hello world"
            },
            {
                "description": "Start an interactive shell session where `echo` is disabled in command output:",
                "command": "cmd {{path}}"
            },
            {
                "description": "Start an interactive shell session with delayed [v]ariable expansion enabled or disabled:",
                "command": "cmd {{path}}:on|off"
            },
            {
                "description": "Start an interactive shell session with command [e]xtensions enabled or disabled:",
                "command": "cmd {{path}}:on|off"
            },
            {
                "description": "Start an interactive shell session with used [u]nicode encoding:",
                "command": "cmd {{path}}"
            }
        ]
    }
}