commands

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 为执行命令的输出
04-28 01:31