zoukankan      html  css  js  c++  java
  • python初步学习-python模块之 commands

    commands

    通过 os.popen() 执行 shell 命令,返回两个对象,一个是 状态码(Int)、另一个为命令输出(str)

    commands.getoutput(cmd)

    返回命令执行输出,包括正确输出或者错误输出。

    commands.getstatus(file)

    查看文件或者目录的状态,类似

    ls -ld file
    

    例如:

    import commands
    print commands.getstatus('/tmp/test')   #/tmp/test是一个目录
    print commands.getstatus('/tmp/test/file.txt')    #file.txt是一个文件
    
    #返回结果:
    >>> import commands
    >>> print commands.getstatus('/tmp/test')
    drwxr-xr-x 2 root root 4096 Oct 27 03:41 /tmp/test
    
    
    >>> print commands.getstatus('/tmp/test/file.txt')
    -rw-r--r-- 1 root root 857 Oct 27 03:41 /tmp/test/file.txt
    
    与 ls -ld 效果一样
    

    commands.getstatusoutput(cmd)

    返回(status,output)

    • status 为执行命令的返回码
    • output 为执行命令的输出
  • 相关阅读:
    三大范式
    html 横线的代码
    CSS下拉 菜单3.27第一次
    JS页面三种打开方式及对话框
    函数整理
    3.22整理作业
    for循环,if 练习
    php测试题
    设计模式
    面向对象的三大特性
  • 原文地址:https://www.cnblogs.com/pingqiang/p/7817984.html
Copyright © 2011-2022 走看看