summaryrefslogtreecommitdiff
path: root/Lib/cmd.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-03-22 21:59:20 +0000
committerGuido van Rossum <guido@python.org>2001-03-22 21:59:20 +0000
commit2811e686026a99048e052554355660a2ad4fe435 (patch)
tree6c41e7f5a15954e95a01d1ad291032a4e89ffa80 /Lib/cmd.py
parent6c4200665ab1e17fcabe5b5e54c9a57792218b2d (diff)
downloadcpython-2811e686026a99048e052554355660a2ad4fe435.tar.gz
This is SF patch #405952, by Anthony Baxter:
cmd.py uses raw_input(); eats SIGCLD: I discovered a rather nasty side effect of the standard cmd.py library today. If it's sitting inside raw_input(), any SIGCLDs that get sent to your application get silently eaten and ignored. I'm assuming that this is something that readline is thoughtfully doing for me. This patch adds an instance attr that allows the user to select to not use raw_input(), but instead use sys.stdin.readline() [Changed slightly to catch EOFError only for raw_input().]
Diffstat (limited to 'Lib/cmd.py')
-rw-r--r--Lib/cmd.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/Lib/cmd.py b/Lib/cmd.py
index dcf601f4f2..10c11a2221 100644
--- a/Lib/cmd.py
+++ b/Lib/cmd.py
@@ -35,7 +35,7 @@ These interpreters use raw_input; thus, if the readline module is loaded,
they automatically support Emacs-like command history and editing features.
"""
-import string
+import string, sys
__all__ = ["Cmd"]
@@ -54,6 +54,7 @@ class Cmd:
misc_header = "Miscellaneous help topics:"
undoc_header = "Undocumented commands:"
nohelp = "*** No help on %s"
+ use_rawinput = 1
def __init__(self): pass
@@ -69,10 +70,18 @@ class Cmd:
line = self.cmdqueue[0]
del self.cmdqueue[0]
else:
- try:
- line = raw_input(self.prompt)
- except EOFError:
- line = 'EOF'
+ if self.use_rawinput:
+ try:
+ line = raw_input(self.prompt)
+ except EOFError:
+ line = 'EOF'
+ else:
+ sys.stdout.write(self.prompt)
+ line = sys.stdin.readline()
+ if not len(line):
+ line = 'EOF'
+ else:
+ line = line[:-1] # chop \n
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)