简体   繁体   中英

Python cmd2 module send commands

I have implemented a custom command line with python cmd2 module.

from cmd2 import Cmd
class CliApp(Cmd):
      .....

Now I also need to send commands to my custom command line from other python project. I tried:

send = CliApp().send
print send('hello')

Which gives the error:

AttributeError: Cmd instance has no attribute 'send'

I have also tried the original example from:

cmd2 - the-send-method - but it gives the same error.

The python cmd2 module which was originally developed by Catherine Devlin around 2008 and has a project page on GitHub under python-cmd2/cmd2 appears to be a completely separate entity from cmd2 module developed around the same time frame by Michele Simionato .

You can read the documentation for the cmd2 module which you can install from PyPI at cmd2.rtfd.io and note that it does NOT have a send method.

To accomplish what you want, I would suggest looking at the cmd2 source code for the onecmd_plus_hooks method and at the cmd2 unit tests which call this method via the run_cmd helper in conftest.py.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM