Created
January 20, 2022 18:52
-
-
Save donno2048/cd7061c01ccce252a16e2683e2cef6c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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