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

需要登入才可留言!

类似文章


docker,cli

Docker容器格式化显示

我觉的如果要写一些自动化功能,或许能够格式化的输出容器内容还满有用的。以下一些Docker容器格式化显示命令的参考范例

fastapi,haproxy

HAProxy与fastapi

HAProxy可以透过acl的定义来决定request要导向那台Backend,本文就来介绍本站的一些设置吧在这里透过path_beg的acl,让送来的request导向其他的服务,而不是域名所指定的后端。

pppoe

如何在ubunut上进行pppoe拨接

如何在ubunut上进行pppoe拨接