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 os
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
@ -8,20 +9,28 @@ 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)
|
||||||
elif command == ("cat"):
|
if command == "exit":
|
||||||
try:
|
exit()
|
||||||
|
elif command == ("cat"):
|
||||||
catFile = input("File to catalog: ")
|
try:
|
||||||
catFileOpened = open(catFile)
|
catFile = input("File to catalog: ")
|
||||||
print(catFileOpened.read())
|
catFileOpened = open(catFile)
|
||||||
except Exception:
|
print(catFileOpened.read())
|
||||||
print("File", catFile, "either doesn't exist or isn't in this directory.")
|
except Exception:
|
||||||
elif command == "version":
|
print("File", catFile, "either doesn't exist or isn't in this directory.")
|
||||||
print(version)
|
elif command == "version":
|
||||||
else:
|
print(version)
|
||||||
subprocess.run(command)
|
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