Added error protection and ^C detection
This commit is contained in:
parent
871c7d3417
commit
ce9b2fd74b
43
main.py
Normal file → Executable file
43
main.py
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
|
@ -8,20 +9,28 @@ version = "0.0.1"
|
|||
|
||||
def grabArgument(fullCommand, commandRan):
|
||||
fullCommand.replace(commandRan, "")
|
||||
|
||||
while True:
|
||||
command = input(currentDirectory + " > ")
|
||||
if command == "pwd":
|
||||
print(currentDirectory)
|
||||
elif command == ("cat"):
|
||||
try:
|
||||
|
||||
catFile = input("File to catalog: ")
|
||||
catFileOpened = open(catFile)
|
||||
print(catFileOpened.read())
|
||||
except Exception:
|
||||
print("File", catFile, "either doesn't exist or isn't in this directory.")
|
||||
elif command == "version":
|
||||
print(version)
|
||||
else:
|
||||
subprocess.run(command)
|
||||
try:
|
||||
while True:
|
||||
command = input(currentDirectory + " > ")
|
||||
if command == "pwd":
|
||||
print(currentDirectory)
|
||||
if command == "exit":
|
||||
exit()
|
||||
elif command == ("cat"):
|
||||
try:
|
||||
catFile = input("File to catalog: ")
|
||||
catFileOpened = open(catFile)
|
||||
print(catFileOpened.read())
|
||||
except Exception:
|
||||
print("File", catFile, "either doesn't exist or isn't in this directory.")
|
||||
elif command == "version":
|
||||
print(version)
|
||||
else:
|
||||
try:
|
||||
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...")
|
||||
|
|
Loading…
Reference in New Issue
Block a user