cmd is a module in the Python Standard Library for writing line-oriented command interpreters.
Questions tagged [python-cmd]
46 questions
9
votes
1 answer
Handle CTRL-C in Python cmd module
I wrote a Python 3.5 application using the cmd module. The last thing I would like to implement is proper handling of the CTRL-C (sigint) signal. I would like it to behave more or less the way Bash does it:
print ^C at the point the cursor is
clear…

wujek
- 10,112
- 12
- 52
- 88
8
votes
2 answers
Python using argparse with cmd
Is there a way to use the argparse module hooked in as the interpreter for every prompt in an interface inheriting from cmd?
I'd like for my cmd interface to interpret the typical line parameter in the same way one would interpret the options and…

DeaconDesperado
- 9,977
- 9
- 47
- 77
7
votes
1 answer
Persistent history in python cmd module
Is there any way to configure the CMD module from Python to keep a persistent history even after the interactive shell has been closed?
When I press the up and down keys I would like to access commands that were previously entered into the shell on…

PJConnol
- 119
- 1
- 9
6
votes
1 answer
Python Twisted integration with Cmd module
I like Python's Twisted and Cmd. I want to use them together.
I got some things working, but so far I haven't figured out how to make tab-completion work, because I don't see how to receive tab keypres events right away (without pressing Enter) in…

John Zwinck
- 239,568
- 38
- 324
- 436
6
votes
2 answers
Create automated tests for interactive shell based on Python's cmd module
I am building an interactive shell using Python 3 and the cmd module. I have already written simple unit tests using py.test to test the individual functions, such as the do_* functions. I'd like to create more comprehensive tests that actually…

doza
- 893
- 1
- 7
- 12
5
votes
1 answer
Python cmd on linux does not autocomplete special characters or symbols
Characters such as - , + etc are not parsed the same way as alphanumeric ASCII characters by Python's readline based cmd module. This seems to be linux specific issue only, as it seems to work as expected on Mac OS.
Sample code
import cmd
class…

rajivRaja
- 527
- 3
- 6
- 16
3
votes
2 answers
Why don't I see errors from readline.set_completion_display_matches_hook?
Consider this code:
#!/usr/bin/env python3
from cmd import Cmd
import readline
class mycmd(Cmd):
def match_display_hook(self, substitution, matches, longest_match_length):
someNonexistentMethod()
print()
for match in…

Joseph Sible-Reinstate Monica
- 45,431
- 5
- 48
- 98
3
votes
2 answers
Change cmd prompt size in Python
I am making a text-based CMD application in Python.
And I'd like it to resize the Command prompt to a more square, Text-based adventure-like, form.
So I found this:
os.system("mode con cols=93 lines=45")
However that's definitive and once set the…

Tom
- 571
- 2
- 11
- 29
3
votes
1 answer
Python: Combination of cmd and asyncio (for WAMP / autobahn)
Overview
I am trying to implement a simple command-line interface for a WAMP application.
For the WAMP implementation, the autobahn python package is used.
I would like to have an interactive shell so I decided to use the cmd module to parse the…

Maximilian Köstler
- 452
- 5
- 15
2
votes
1 answer
Python cmd autocomplete: display options on separate lines
I am writing a CLI in Python using the cmd module, which provides the autocomplete functionality using the readline module.
Autocomplete shows the different options on the same line, while I want them on different lines, and I have not find any…

Amedeo
- 847
- 7
- 17
2
votes
0 answers
How to stop user input from appearing in history in cmd module?
Consider this minimal program that uses the cmd module:
import cmd
class Shell(cmd.Cmd):
def do_input(self, _arg):
'''Ask the user to input a string.'''
s = input('String: ')
print(s)
if __name__ == '__main__':
…

Flux
- 9,805
- 5
- 46
- 92
2
votes
2 answers
multi-word commands in custom python interactive shell
I'm trying to build a small interactive shell in Python using the cmd module. Is there an easy way to allow for multi-word commands?
For example, it's easy to process the hello command
class FooShell(Cmd):
def do_hello(self, args):
…

Daniel Kats
- 5,141
- 15
- 65
- 102
2
votes
0 answers
How to call Python Cmd instance remotely/programmatically, replacing stdin and stdout pipes?
I'd like to have a Python Cmd instance running in a separate thread, and be able to write input and read output from other parts of my program.
In the constructor of Cmd, it is possible to specify stdin(default: sys.stdin) and stdout(default…

celtichindu
- 33
- 1
- 4
1
vote
1 answer
Python cmd dynamic docstrings for do_help() function
I'm working on a Pythonic command-line "flashcard" app for helping users learn different languages. I would like to use Python's cmd library to speed up development--of particular interest is the cmd.Cmd class's do_help() method, which prints off…

weberc2
- 7,423
- 4
- 41
- 57
1
vote
1 answer
How to make prompt (>>>) in center of Python IDLE
I am writing code in python shell when I enough writing code prompt(that angle bracket goes to bottom of the shell which is quite difficult to record something with that).
Check this image how my angle bracket are in the bottom of the shell
prompt…

Azhar Uddin Sheikh
- 527
- 8
- 23