在Python语法中有哪些自带的系统命令,这些命令如何调用?下面web建站小编给大家简单介绍一下!
os.popen方法
import os result = os.popen('cat /etc/passwd') print(result.read())
os.popen()
方法不仅执行命令而且返回执行后的信息对象
import os result = os.system('cat /etc/passwd') print(result) # 0
os.system
方法是直接调用标准C的system() 函数,仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息。
import subprocess res = subprocess.Popen('cat /etc/passwd', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # 使用管道 print res.stdout.read() # 标准输出 for line in res.stdout.readlines(): print line res.stdout.close() # 关闭
subprocess
是一个功能强大的子进程管理模块,是替换os.system,os.spawn*
等方法的一个模块。
import commands status = commands.getstatus('cat /etc/passwd') print(status) output = commands.getoutput('cat /etc/passwd') print(output) (status, output) = commands.getstatusoutput('cat /etc/passwd') print(status, output)
Mac电脑安装Python软件后怎么查看版本号(附下载地址)
上面是“Python语法中有哪些系统命令(如何调用)”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4590.html
workflows工作流
一颗柔和的水晶金字塔ComfyUI工作流
一个红头发明亮眼睛的漂亮女人
树枝上一只色彩斑斓的小鸟
一位老人安详地坐在云层中钓鱼
一套可爱的动漫生物蓬松贴纸图标
一个极其美丽细致的女孩ComfyUI工作流
爱因斯坦在做实验3d动漫ComfyUI工作流
一只白色的孔雀ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!