python交互式shell,使用cmd重复语句,不键入任何参数

python交互式shell,使用cmd重复语句,不键入任何参数,shell,python-2.7,python-cmd,Shell,Python 2.7,Python Cmd,python新手,我正在使用cmd开发一个交互式shell,它接受定义的函数和参数,并以if/then格式返回值。下面的例子。但我的问题是,每次用户键入一个函数,我都会向用户返回一些东西,如果他们只是按enter键,那么他们就会收到最后提供的输出 例如下面的代码……但基本上,如果用户没有为此键入参数或函数,我只希望不显示任何内容,只显示“”或空白。我以为else pass的论点会对我起作用,但显然不是。我试过if和elif,结果都一样 示例输出为“test arp”,只需按enter键即可返回上

python新手,我正在使用cmd开发一个交互式shell,它接受定义的函数和参数,并以if/then格式返回值。下面的例子。但我的问题是,每次用户键入一个函数,我都会向用户返回一些东西,如果他们只是按enter键,那么他们就会收到最后提供的输出

例如下面的代码……但基本上,如果用户没有为此键入参数或函数,我只希望不显示任何内容,只显示“”或空白。我以为else pass的论点会对我起作用,但显然不是。我试过if和elif,结果都一样

示例输出为“test arp”,只需按enter键即可返回上一个按下的参数:

user@hostname>test arp
? (192.168.50.1) at 0:26:88:38:c6:48 on en0 ifscope [ethernet]
? (192.168.50.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
> **<enter key>**
? (192.168.50.1) at 0:26:88:38:c6:48 on en0 ifscope [ethernet]
? (192.168.50.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
> **<enter key>**

cmd文档首页的右侧讨论了禁用返回上一个命令选项


Geez通常帮助阅读cmd模块文档。为了胜利!def排空管路(自身):通过
from cmd import Cmd
from time import ctime
import csv, os, subprocess, getpass, socket, pwd, re, select, shutil, subprocess, sys

syntaxError = "Sorry that syntax isn't quite right..."

class cliPrompt(Cmd):

    def do_test(self, args):
        if len(args) == 0:
            print syntaxError  
        if args == '?':
            print 'want to read the help?'
        if args == 'arp':
            subprocess.call('arp -an', shell=True)
        if args == 'cpu':
            subprocess.call('grep "model name" /proc/cpuinfo', shell=True)
        if args == 'firewall':
            subprocess.call('iptables -L -v -n --line-numbers', shell=True)
        if args == 'interfaces':
            subprocess.call('ifconfig', shell=True)
        else: 
            pass                                            

if __name__ == '__main__':
    prompt = cliPrompt()
    prompt.prompt = '>'
    prompt.cmdloop()