Added error protection and ^C detection

This commit is contained in:
Maxwell 2024-07-03 13:09:47 +10:00
parent 871c7d3417
commit ce9b2fd74b

15
main.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/python
import os import os
import subprocess import subprocess
import re import re
@ -8,14 +9,15 @@ version = "0.0.1"
def grabArgument(fullCommand, commandRan): def grabArgument(fullCommand, commandRan):
fullCommand.replace(commandRan, "") fullCommand.replace(commandRan, "")
try:
while True: while True:
command = input(currentDirectory + " > ") command = input(currentDirectory + " > ")
if command == "pwd": if command == "pwd":
print(currentDirectory) print(currentDirectory)
if command == "exit":
exit()
elif command == ("cat"): elif command == ("cat"):
try: try:
catFile = input("File to catalog: ") catFile = input("File to catalog: ")
catFileOpened = open(catFile) catFileOpened = open(catFile)
print(catFileOpened.read()) print(catFileOpened.read())
@ -24,4 +26,11 @@ while True:
elif command == "version": elif command == "version":
print(version) print(version)
else: else:
try:
subprocess.run(command) subprocess.run(command)
except Exception:
print("Command", command, "either doesn't exist, isn't in the path or isn't in this directory.")
except Exception:
print("Looks like there was an error. Exiting...")
except KeyboardInterrupt:
print(" detected! Exiting...")