25

I'm currently trying to make some small shell-like utility for a custom script I wrote, so I can easily work with it (it's rather simple, so an interactive shell would be perfect).

Do you have any resources for me on how to create a shell in Python? I spent googling for a while, but all I could find was information about IDLE and similar Python interpreters. But I would rather want to know how to write a completely custom and command line based shell.

My approach would be hooking the stdin/out for commands, but given that the Python library offers so many great utilities, I want to make sure there if there is no better way.

poke
  • 369,085
  • 72
  • 557
  • 602

2 Answers2

27

The cmd module in the standard library could be a start -- if you have any trouble using it, please post more specific questions (ideally with some toy example showing what you're trying to achieve and what you're getting instead!).

Flimm
  • 136,138
  • 45
  • 251
  • 267
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • another python library ishell also serves this purpose. https://github.com/italorossi/ishell – Veena Jan 25 '19 at 10:27
1

You might have a look at pyparsing. It is definitely only about lexing and parsing, but that's definitely the hardest part of the problem.

teepark
  • 1,795
  • 13
  • 10