时间:2023-03-13 12:12:54 | 栏目:Python代码 | 点击:次
commands模块是python的内置模块,他共有三个函数,使用help(commands)可以查看到
FUNCTIONS getoutput(cmd) Return output (stdout or stderr) of executing cmd in a shell. getstatus(file) Return output of "ls -ld <file>" in a string. getstatusoutput(cmd) Return (status, output) of executing cmd in a shell.
status代表的shell命令的返回状态,如果成功的话是0;output是shell的返回的结果
>>> import commands >>> status, output = commands.getstatusoutput("ls") >>> print status 0 >>> print output atom: bookstore cookie.py~
commands.getstatus(file)
commands.getoutput(cmd)
>>> print commands.getoutput("ls") atom: bookstore cookie.py~
commands 模块是 Python 的内置模块,它主要有三个函数:
函数 | 说明 |
---|---|
getoutput(cmd) | Return output (stdout or stderr) of executing cmd in a shell. |
getstatus(file) | Return output of “ls -ld file” in a string. |
getstatusoutput(cmd) | Return (status, output) of executing cmd in a shell. |