Skip to content

Instantly share code, notes, and snippets.

@donno2048
Created January 20, 2022 18:52
Show Gist options
  • Save donno2048/cd7061c01ccce252a16e2683e2cef6c0 to your computer and use it in GitHub Desktop.
Save donno2048/cd7061c01ccce252a16e2683e2cef6c0 to your computer and use it in GitHub Desktop.
# Simple python shell
## Use:
### In cmd:
#### python3 shell.py
#### echo "ls" | python3 shell.py
### In python:
#### main("ls")
from os import name, popen, getcwd
from sys import stdin, exit
if name != 'nt': import readline
def main(command = None, raw = False):
if command is not None:
print(popen(command).read(), end = '')
if not raw: return
if not stdin.isatty(): main(stdin.read())
else:
try: main(input(getcwd() + '$ '), True)
except KeyboardInterrupt: exit(str()) # make sure to move a line down
if __name__ == '__main__': main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment