games:x:5:60:games:/usr/games:/usr/sbin/nologin
可以help(output) 获取相关帮助去操作这个output
3、commands 模块
这个模块主要提供了三个方法:
(1)、getoutput(cmd)
Return output (stdout or stderr) of executing cmd in a shell.
返回一个shell 命令的标准输出或者时错误输出
In [17]: commands.getoutput('ls /home -l')
Out[17]: 'total 4\ndrwxr-xr-x 31 admin admin 4096 5\xe6\x9c\x88 3 09:48 admin'
In [18]: commands.getoutput('ls /homeaaa -l')
Out[18]: 'ls: cannot access /homeaaa: No such file or directory'
(2)、getstatus(file)
Return output of "ls -ld <file>" in a string.
获取一个文件的状态。 相当于执行了 ls -ld file
In [25]: commands.getstatus('/bin/ls')
Out[25]: '-rwxr-xr-x 1 root root 110080 3\xe6\x9c\x88 24 2014 /bin/ls' // 相当于执行了 ls -ld /bin/ls
In [26]: os.system('ls -ld /bin/ls')
-rwxr-xr-x 1 root root 110080 3月 24 2014 /bin/ls
(3)、getstatusoutput(cmd)
Return (status, output) of executing cmd in a shell.
返回shell 的状态码和输出结果
In [20]: commands.getstatusoutput('ls /home -l')
Out[20]: (0, 'total 4\ndrwxr-xr-x 31 admin admin 4096 5\xe6\x9c\x88 3 09:48 admin')
In [21]: commands.getstatusoutput('ls /homeaa -l')
Out[21]: (512, 'ls: cannot access /homeaa: No such file or directory')
4、subprocess 相关模块.
从这个模块的帮助中可以看到。它的一个很主要的目的就是要替代掉os.system 、os.spawn*、os.popen*、popen2.* 、commands.* 这些模块的功能
subproces 模块中一个很强大的类Popen,我们的主要学习重点应该在于此