在python解释器中运行shell命令

这个问题在这里已经有了答案:

  • 在Python中调用外部命令50个答案

  • 在普通的python中,你需要使用以下内容:

    from subprocess import check_output
    check_output("ls", shell=True)
    

    在IPython中,你可以运行这些命令或者一个通用的shell命令,从头开始! 。 例如

    ! echo "Hello, world!" > /tmp/Hello.txt
    

    如果您以交互方式使用python,那么您几乎肯定会对IPython感到高兴。


    如果您打算在调用命令(ls,pwd,...)时交互使用Python shell,请查看iPython。

    链接地址: http://www.djcxy.com/p/13509.html

    上一篇: Running shell commands within python interpreter

    下一篇: Putting nested bash command in Python