pythonshellinteractivereadlineinteractive-shell

Extending the Python interactive shell


I'd like to extend the Python interactive shell to allow execution of non-python specific statements or commands. The idea being, if you type something on the prompt that would raise a NameError what you typed could be parsed for known external commands, and only it failing to find an external command, raise the NameError.

I'm not quite sure where to start, I tried calling code.InteractiveConsole().interact() inside a try: / except NameError but that didn't work

I read the documentation for the cmd module, but I looks like its designed JUST for calling external commands and ignores python statements.

The goal is a simple (its for a very small, GUI-less system) command shell that can be scripted with python (rather than sh)

Where should I be looking? A pure Python solution is ideal.


Solution

  • Have a look at this documentation: http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html
    When it becomes using python as a shell replacement, I think are pretty much covered.