我正在尝试使用pwd,ls和touch等命令编写shell。并且不想使用os库。我想使用sqlite在本地数据库中实现命令。有人知道该怎么做吗?
import subprocess
import sqlite3
path = 'root:'
class db:
db_file = r'C:\Users\Desktop\myDB.db'
def __init__(self, db_file):
conn = None
try:
self.conn = sqlite3.connect(db_file)
except Error as e:
print(e)
def execute_commands(command):
##################
def main():
while True:
command = input("> ")
if command == "exit":
break
elif command == "help":
print("psh: a shell written in python")
else:
execute_commands(command)
if '__main__' == __name__:
main()
我建议您使用库cmd。它非常适合创建自己的shell:)