在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工作流
一幅3D农场游戏画面ComfyUI工作流
一个神秘的隐藏面孔下一本书的剪影ComfyUI工作流
一只沮丧的卡通小丑鱼ComfyUI工作流
一只透明老虎骨骼标本ComfyUI工作流
一头巨大的古代大象背后建着一座城市
一座千年九尾白狐玉雕ComfyUI工作流
一只千纸鹤坐在路上哭泣ComfyUI工作流
一只外星甲壳虫子ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用js+css3做一个小鱼游泳特效
css3实现星球旋转
用svg画出游泳池动画效果
js实现下雪特效
数字滚动效果(兼容IE6/IE8)
canvas经线动画走到效果
html5如何3D立方体旋转特效
如何利用svg做一个有趣的loading动画加载










