by Devin Yang

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

最简化版本的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

需要登入才可留言!

类似文章


linux

Raspberry Pi 3 树莓派作业系统安装

这篇文章,分享使用MacOS上的内建命令,进行Raspberry Pi的作业系统安装。 在这个安装过程中关於dd命令,请小心指定您of的参数,即是write output到文件的位置, 指定错了,会毁掉自己的系统哦。

zsh

停用zsh贴连结到Terminal时自动加escape的功能

有时电脑真的做的太自动了,自动过头了,有些功能我就不是很喜欢,像是zsh上贴数据自动补反斜线。 如何停用呢? 我找到罗。

fastapi,haproxy

HAProxy与fastapi

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