日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網(wǎng)站首頁 編程語言 正文

python?commands模塊的適用方式_python

作者:以我丶之姓 ? 更新時間: 2022-04-18 編程語言

commands模塊的適用

commands模塊是python的內(nèi)置模塊,他共有三個函數(shù),使用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.

1、 commands.getstatusoutput(cmd)返回一個元組(status,output)

status代表的shell命令的返回狀態(tài),如果成功的話是0;output是shell的返回的結(jié)果

>>> import commands
>>> status, output = commands.getstatusoutput("ls")
>>> print status
0
>>> print output
atom:
bookstore
cookie.py~

2、返回ls -ld file執(zhí)行的結(jié)果

commands.getstatus(file)

3、判斷Shell命令的輸出內(nèi)容

commands.getoutput(cmd)
>>> print commands.getoutput("ls")
atom:
bookstore
cookie.py~

commands 方法

commands 模塊是 Python 的內(nèi)置模塊,它主要有三個函數(shù):

函數(shù) 說明
getoutput(cmd) Return output (stdout or stderr) of executing cmd in a shell.
getstatus(file) Return output of “l(fā)s -ld file” in a string.
getstatusoutput(cmd) Return (status, output) of executing cmd in a shell.

原文鏈接:https://www.jianshu.com/p/d29b8a2119ad

欄目分類
最近更新