【问题标题】:Command line interface for python [duplicate]python的命令行界面[重复]
【发布时间】:2016-05-11 09:50:40
【问题描述】:

我想用python创建一个程序,当程序运行时,它会显示自己的命令行界面。用户可以在界面中输入命令,程序将处理该命令。有没有办法在Windows 和 Linux 环境中做到这一点?

【问题讨论】:

    标签: python linux windows


    【解决方案1】:

    这应该适用于 linux 和 windows:

    from subprocess import call
    
    while True:
        print call(raw_input("command: "), shell = True)
    

    【讨论】:

    • 感谢您的回答,但据我所知 raw_input() 函数在 Windows 中不起作用
    • @Waveter 有效,但仅适用于 python 2.x,如果你有 python 3.x,你应该使用 str(input("command: "))
    猜你喜欢
    • 2016-11-10
    • 1970-01-01
    • 2017-08-04
    • 2020-05-31
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多