by Devin Yang

建立于: 7年前 ( 更新: 7年前 )

最简化版本的Python系统命令运行范本

#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE, STDOUT
#运行的命令
command='ls -l'.split()
proc=Popen(command , stdout=PIPE,stderr=PIPE, universal_newlines=True);
output, error = proc.communicate()

#显示运行结果
if(proc.poll()==0):
     print(output)
else:
     print("{} Error\n".format(error))


 

Tags:

Devin Yang

文章内容无法一一说明,如果您有什么不了解处,欢印提问哦:)

No Comment

Post your comment

需要登入才可留言!

类似文章


python

python fastapi速查笔记

简单日志运行fastapi的安装步骤

docker

Devin Yang的Docker初学笔记

这是我初学Docker时的笔记,有点粗糙,有调整了一下下。 但我想对於Docker初学者,应该可以提供一些初步的概念, 欢迎参考看看。

docker

用bash更新docker-compse版本

安装最新版本的docker-compose