Python 官方文档:入门教程 => 点击学习
目录commands模块的适用1、 commands.getstatusoutput(cmd)返回一个元组(status,output)2、返回ls -ld file执行的结果3、判
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. |
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: pythoncommands模块的适用方式
本文链接: https://www.lsjlt.com/news/138911.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0