1

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.

tMC
  • 18,105
  • 14
  • 62
  • 98
  • IPython does exactly this. I would start by checking out its [InteractiveShell](http://ipython.scipy.org/doc/manual/html/api/generated/IPython.core.interactiveshell.html) and [Magic](http://ipython.scipy.org/doc/manual/html/api/generated/IPython.core.magic.html) classes. – Pete May 24 '11 at 21:27

1 Answers1

1

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.