command模块是Python的一个标准库,用于执行系统命令。你可以使用command模块来调用外部命令,并获取命令的输出结果。
以下是command模块的基本使用方法:
import command
output = command.getoutput('command')
print(output)
其中,'command’是要执行的系统命令,getoutput()函数会返回命令的输出结果。
status, output = command.getstatusoutput('command')
print(status)
print(output)
其中,getstatusoutput()函数会返回命令的执行状态和输出结果,status为命令的退出状态,output为命令的输出结果。
另外,command模块还提供了其他一些函数来执行命令,如:
command.getstatus('command')
:执行命令,返回命令的退出状态。command.getoutputerror('command')
:执行命令,返回命令的输出结果和错误信息。注意:command模块已在Python 2中弃用,推荐使用subprocess模块来执行系统命令。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:python的command模块怎么用