Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

python - Why am i always geting the command not recognized output

This are the commands the commands the host can enter

    elif 'command' == "custom_dir":
        conn.send(command.encode())
        print("")
        user_input = input(str("Custom Dir : "))
        conn.send(user_input.encode())
        print("")
        print("Command has been sent")
        print("")
        files = conn.recv(5000)
        files = files.decode()
        print("Custom Dir Result : ", files)
    else:
        print("")
        print("Command not recognized")

This is the person that gets sent this commands (Sometimes this crashes)

    elif 'command' == "custom_dir":
        user_input = s.recv(5000)
        user_input = user_input.decode()
        files = os.listdir(user_input)
        files = str(files)
        s.send(files.encode())
        print("")
        print("Command has been executed successfully...")
        print("")
    else:
        print("")
        print("Command not recognized")

Even if i change the 'command' to command i still get the same output

question from:https://stackoverflow.com/questions/65601870/why-am-i-always-geting-the-command-not-recognized-output

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

'command' is a string literal. The string 'command' will never be equal to the string "custom_dir". It's the same as 5 == 6 - they will never be equal.

Did you mean to refer to a variable called command? In that case, write:

elif command == "custom_dir":

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...