網站首頁 編程語言 正文
commands模塊的適用
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.
1、 commands.getstatusoutput(cmd)返回一個元組(status,output)
status代表的shell命令的返回狀態,如果成功的話是0;output是shell的返回的結果
>>> import commands >>> status, output = commands.getstatusoutput("ls") >>> print status 0 >>> print output atom: bookstore cookie.py~
2、返回ls -ld file執行的結果
commands.getstatus(file)
3、判斷Shell命令的輸出內容
commands.getoutput(cmd)
>>> print commands.getoutput("ls") atom: bookstore cookie.py~
commands 方法
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. |
原文鏈接:https://www.jianshu.com/p/d29b8a2119ad
相關推薦
- 2022-11-19 Golang?cron?定時器和定時任務的使用場景_Golang
- 2024-03-25 一個實體類有多個數據,不寫xml,用mybatisplus進行查詢
- 2022-06-08 SpringBoot jar包瘦身操作 -Dloader.path使用
- 2022-06-21 Android?Studio實現彈窗設置_Android
- 2022-10-14 基于數據庫自定義UserDetailsService實現JWT認證
- 2023-03-15 Android?Studio?全局查找問題_Android
- 2022-07-26 Visual Studio上一些Error的解決方案
- 2022-05-15 Web?API中使用Autofac實現依賴注入_實用技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支