Python Forum
Small command shell - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: Small command shell (/thread-33105.html)



Small command shell - Adrian_L - Mar-29-2021

Hi there! Got code! Down here |
import os
print("mini command line v1.0.0")
print("type help for a list of commands.")
print("")

def commandline():
    commandline = input("C:\\system\\commands>")
    return commandline

commands = ["help", "dir", "exit"]

commandline_string = ""
while commandline_string != "exit":
    commandline_string = commandline()

    if not commandline_string in commands and commandline_string != "":
        print("Unable to run command. Please check that the command exists and that you have permission to use it.")

    if commandline_string == "help":
        print("These are the valid commands")
        for command in commands:
            print(command)

    elif commandline_string == "dir":
        files = os.listdir("/")
        for file in files:
            print(file)

    elif commandline_string == "dir /?":
        print("the dir command will display your computer directories.")

    elif commandline_string == "exit /?":
        print("the exit command will exit the XC command line command interpreter.")
That is the code for a mini command line. I did not know how to add files so...


RE: Small command shell - joe_momma - Mar-30-2021

If you mouse over the tool bar icons it's the blue and yellow one, when you hoover over it it says "insert python". Put your code between the tags please


RE: Small command shell - Adrian_L - Mar-30-2021

Thanks for the help. I will do that next time.